-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
53 lines (46 loc) · 1.14 KB
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package conversation
import (
"fmt"
"github.com/EricJSanchez/wecom/WeWorkFinanceSDK"
"github.com/spf13/cast"
"time"
)
// GetMessageInstance 获取会话归档实例
func (r *Client) GetMessageInstance() (client *WeWorkFinanceSDK.Client, err error) {
client, err = WeWorkFinanceSDK.NewClient(r.corpID, r.secret, r.rasPrivateKey)
if err != nil {
fmt.Println("SDK 初始化失败:", err)
}
return
}
// SetMessageSeq 设置消息seq
func (r *Client) SetMessageSeq(newSeq uint64) (seq uint64, err error) {
r.seqLock.Lock()
defer r.seqLock.Unlock()
seqCacheKey := fmt.Sprintf("wx:seq:%s", r.corpID)
if val := r.cache.Get(seqCacheKey); val != nil {
seq = cast.ToUint64(val)
} else {
seq = 0
}
if newSeq > seq {
err = r.cache.Set(seqCacheKey, newSeq, time.Duration(720)*time.Hour)
if err != nil {
return
}
seq = newSeq
}
return
}
// GetMessageSeq 获取消息seq
func (r *Client) GetMessageSeq() (seq uint64, err error) {
r.seqLock.RLock()
defer r.seqLock.RUnlock()
seqCacheKey := fmt.Sprintf("wx:seq:%s", r.corpID)
if val := r.cache.Get(seqCacheKey); val != nil {
seq = cast.ToUint64(val)
} else {
seq = 0
}
return
}