-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
729 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
.DS_Store | ||
|
||
/.idea | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
.DS_Store | ||
|
||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,84 @@ | ||
# WeWorkFinanceSDK | ||
企业微信会话存档SDK(基于企业微信C版官方SDK封装),暂时只支持在`linux`环境下使用当前SDK。 | ||
|
||
### 使用方式 | ||
|
||
`clone`项目到自己项目内并`cd`到`WeWorkFinanceSDK/lib`文件夹内执行`export LD_LIBRARY_PATH=$(pwd)`命令设置动态链接库检索地址,然后在项目内引入当前包即可直接使用。 | ||
|
||
### Example | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/NICEXAI/WeWorkFinanceSDK" | ||
) | ||
|
||
func main() { | ||
corpID := "xxxxxxxxxxxx" | ||
corpSecret := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
rsaPrivateKey := ` | ||
-----BEGIN RSA PRIVATE KEY----- | ||
xxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
-----END RSA PRIVATE KEY----- | ||
` | ||
//初始化客户端 | ||
client, err := WeWorkFinanceSDK.NewClient(corpID, corpSecret, rsaPrivateKey) | ||
if err != nil { | ||
fmt.Printf("SDK 初始化失败:%v \n", err) | ||
return | ||
} | ||
//获取消息 | ||
chatDataList, err := client.GetChatData(0, 100, "", "", 3) | ||
if err != nil { | ||
fmt.Printf("消息同步失败:%v \n", err) | ||
return | ||
} | ||
for _, chatData := range chatDataList { | ||
//消息解密 | ||
chatInfo, err := client.DecryptData(chatData.EncryptRandomKey, chatData.EncryptChatMsg) | ||
if err != nil { | ||
fmt.Printf("消息解密失败:%v \n", err) | ||
return | ||
} | ||
str, _ := json.Marshal(chatInfo) | ||
fmt.Println(string(str)) | ||
} | ||
} | ||
``` | ||
# WeWorkFinanceSDK | ||
企业微信会话存档SDK(基于企业微信C版官方SDK封装),暂时只支持在`linux`环境下使用当前SDK。 | ||
|
||
### 官方文档地址 | ||
https://open.work.weixin.qq.com/api/doc/90000/90135/91774 | ||
|
||
### 使用方式 | ||
|
||
`clone`项目到自己项目内并`cd`到`WeWorkFinanceSDK/lib`文件夹内执行`export LD_LIBRARY_PATH=$(pwd)`命令设置动态链接库检索地址,然后在项目内引入当前包即可直接使用。 | ||
|
||
### Example | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/NICEXAI/WeWorkFinanceSDK" | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
) | ||
|
||
func main() { | ||
corpID := "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | ||
corpSecret := "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | ||
rsaPrivateKey := `XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX` | ||
|
||
//初始化客户端 | ||
client, err := WeWorkFinanceSDK.NewClient(corpID, corpSecret, rsaPrivateKey) | ||
if err != nil { | ||
fmt.Printf("SDK 初始化失败:%v \n", err) | ||
return | ||
} | ||
|
||
//同步消息 | ||
chatDataList, err := client.GetChatData(0, 100, "", "", 3) | ||
if err != nil { | ||
fmt.Printf("消息同步失败:%v \n", err) | ||
return | ||
} | ||
|
||
for _, chatData := range chatDataList { | ||
//消息解密 | ||
chatInfo, err := client.DecryptData(chatData.EncryptRandomKey, chatData.EncryptChatMsg) | ||
if err != nil { | ||
fmt.Printf("消息解密失败:%v \n", err) | ||
return | ||
} | ||
|
||
if chatInfo.Type == "image" { | ||
image := chatInfo.GetImageMessage() | ||
sdkfileid := image.Image.SdkFileId | ||
|
||
isFinish := false | ||
buffer := bytes.Buffer{} | ||
for !isFinish { | ||
//获取媒体数据 | ||
mediaData, err := client.GetMediaData("", sdkfileid, "", "", 5) | ||
if err != nil { | ||
fmt.Printf("媒体数据拉取失败:%v \n", err) | ||
return | ||
} | ||
buffer.Write(mediaData.Data) | ||
if mediaData.IsFinish { | ||
isFinish = mediaData.IsFinish | ||
} | ||
} | ||
filePath, _ := os.Getwd() | ||
filePath = path.Join(filePath, "test.png") | ||
err := ioutil.WriteFile(filePath, buffer.Bytes(), 0666) | ||
if err != nil { | ||
fmt.Printf("文件存储失败:%v \n", err) | ||
return | ||
} | ||
break | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.