WeWorkFinanceSDK
v1.3.0
Enterprise WeChat conversation archiving SDK (based on the official SDK package of Enterprise WeChat C version) currently only supports the use of the current SDK in linux
environment.
https://open.work.weixin.qq.com/api/doc/90000/90135/91774
1. Install go module
go get -u github.com/NICEXAI/WeWorkFinanceSDK
2. Copy libWeWorkFinanceSdk_C.so
dynamic library file from github.com/NICEXAI/WeWorkFinanceSDK/lib
folder to the system dynamic link library default folder, or copy it to any folder and execute export LD_LIBRARY_PATH=$(pwd)
command to set the dynamic link library search address
3. Introduce module
into the project and use it
package main
import (
"bytes"
"fmt"
"github.com/NICEXAI/WeWorkFinanceSDK"
"io/ioutil"
"os"
"path"
)
func main () {
corpID := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
corpSecret := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
rsaPrivateKey := `
-----BEGIN RSA PRIVATE KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----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
}
if chatInfo . Type == "image" {
image := chatInfo . GetImageMessage ()
sdkfileid := image . Image . SdkFileID
isFinish := false
buffer := bytes. Buffer {}
index_buf := ""
for ! isFinish {
//获取媒体数据
mediaData , err := client . GetMediaData ( index_buf , sdkfileid , "" , "" , 5 )
if err != nil {
fmt . Printf ( "媒体数据拉取失败:%v n " , err )
return
}
buffer . Write ( mediaData . Data )
if mediaData . IsFinish {
isFinish = mediaData . IsFinish
}
index_buf = mediaData . OutIndexBuf
}
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
}
}
}