-
Notifications
You must be signed in to change notification settings - Fork 165
/
client.go
62 lines (46 loc) · 1.82 KB
/
client.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
54
55
56
57
58
59
60
61
62
package message
import (
"context"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/work/accountService/message/request"
"github.com/ArtisanCloud/PowerWeChat/v3/src/work/accountService/message/response"
)
type Client struct {
BaseClient *kernel.BaseClient
}
func NewClient(app kernel.ApplicationInterface) (*Client, error) {
baseClient, err := kernel.NewBaseClient(&app, nil)
if err != nil {
return nil, err
}
return &Client{
baseClient,
}, nil
}
// 读取消息
// https://developer.work.weixin.qq.com/document/path/94670
func (comp *Client) SyncMsg(ctx context.Context, cursor string, token string, limit int) (*response.ResponseMessageSyncMsg, error) {
result := &response.ResponseMessageSyncMsg{}
options := &object.HashMap{
"cursor": cursor,
"token": token,
"limit": limit,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/kf/sync_msg", options, nil, nil, result)
return result, err
}
// 发送消息
// https://developer.work.weixin.qq.com/document/path/90236
func (comp *Client) SendMsg(ctx context.Context, messages *request.RequestAccountServiceSendMsg) (*response.ResponseAccountServiceSendMsg, error) {
result := &response.ResponseAccountServiceSendMsg{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/kf/send_msg", messages, nil, nil, result)
return result, err
}
// 发送消息
// https://developer.work.weixin.qq.com/document/path/95122
func (comp *Client) SendMsgOnEvent(ctx context.Context, messages *request.RequestAccountServiceSendMsgOnEvent) (*response.ResponseAccountServiceSendMsgOnEvent, error) {
result := &response.ResponseAccountServiceSendMsgOnEvent{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/kf/send_msg_on_event", messages, nil, nil, result)
return result, err
}