WeWorkFinanceSDK
v1.3.0
企業微信會話存檔SDK(基於企業微信C版官方SDK封裝),暫時只支援在linux
環境下使用目前SDK。
https://open.work.weixin.qq.com/api/doc/90000/90135/91774
1.安裝go module
go get -u github.com/NICEXAI/WeWorkFinanceSDK
2.從github.com/NICEXAI/WeWorkFinanceSDK/lib
資料夾下複製libWeWorkFinanceSdk_C.so
動態庫檔案到系統動態連結庫預設資料夾下,或複製到任意資料夾並在目前資料夾下執行export LD_LIBRARY_PATH=$(pwd)
指令設定動態連結庫檢索位址
3.把module
引入專案中即可使用
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
}
}
}