用于拉取企业聊天记录与媒体消息,该SDK是对官方linux c库的封装
package main
import (
"log"
"fmt"
"bytes"
sdk "github.com/bububa/WeWorkFinanceSDK"
)
func main() {
corpId := "企业ID"
corpSecret := "secret"
clt, err := sdk.NewClient(corpId, corpSecret)
if err != nil {
log.Fatalln(err)
}
defer clt.Destroy()
var (
seq uint64
limit uint64 = 1000
proxy = ""
passwd = ""
timeout = 300
)
for {
chatsData, err := clt.GetChatData(seq, limit, proxy, passwd, timeout)
if err != nil {
log.Fatalln(err)
}
if len(chatsData) == 0 {
break
}
// iterate chatsData
for _, data := range chatsData {
// update seq with chatdata.Seq for next loop
seq = data.Seq
// decrypt chat data
msg, err := clt.DecryptData(data.EncryptRandomKey, data.EncryptChatMsg)
if err != nil {
log.Fatalln(err)
continue
}
fmt.Printf("msg: %+v\n", msg)
if msg.MessageType() == sdk.IMG_MSG {
var (
w = new(bytes.Buffer)
sdkField = msg.(sdk.ImageMessage).SdkFileId
)
err := clt.DownloadMedia(w, sdkField, proxy, passwd, timeout)
if err != nil {
log.Fatalln(err)
continue
}
log.Printf("download mediadata, len:%d bytes\n", w.Len())
}
}
}
}