-
Notifications
You must be signed in to change notification settings - Fork 147
/
client.go
123 lines (95 loc) · 3.76 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package message
import (
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel/messages"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel/power"
response2 "github.com/ArtisanCloud/PowerWeChat/v2/src/kernel/response"
"github.com/ArtisanCloud/PowerWeChat/v2/src/work/message/request"
"github.com/ArtisanCloud/PowerWeChat/v2/src/work/message/response"
)
type Client struct {
*kernel.BaseClient
}
func NewClient(app kernel.ApplicationInterface) *Client {
return &Client{
kernel.NewBaseClient(&app, nil),
}
}
func (comp *Client) Message(message *messages.Message) *Messager {
m := &Messager{
Client: comp,
}
m.Message(message)
return m
}
// 发送应用消息
// https://work.weixin.qq.com/api/doc/90000/90135/90236
func (comp *Client) Send(messages interface{}) (*response.ResponseMessageSend, error) {
result := &response.ResponseMessageSend{}
_, err := comp.HttpPostJson("cgi-bin/message/send", messages, nil, nil, result)
return result, err
}
// SendText 文本消息
func (comp *Client) SendText(messages *request.RequestMessageSendText) (*response.ResponseMessageSend, error) {
return comp.Send(messages)
}
// SendImage 图片消息
func (comp *Client) SendImage(messages *request.RequestMessageSendImage) (*response.ResponseMessageSend, error) {
return comp.Send(messages)
}
// SendVoice 语音消息
func (comp *Client) SendVoice(messages *request.RequestMessageSendVoice) (*response.ResponseMessageSend, error) {
return comp.Send(messages)
}
// SendVideo 视频消息
func (comp *Client) SendVideo(messages *request.RequestMessageSendVideo) (*response.ResponseMessageSend, error) {
return comp.Send(messages)
}
// SendFile 文件消息
func (comp *Client) SendFile(messages *request.RequestMessageSendFile) (*response.ResponseMessageSend, error) {
return comp.Send(messages)
}
// SendTextCard 文本卡片消息
func (comp *Client) SendTextCard(messages *request.RequestMessageSendTextCard) (*response.ResponseMessageSend, error) {
return comp.Send(messages)
}
// SendNews 图文消息
func (comp *Client) SendNews(messages *request.RequestMessageSendNews) (*response.ResponseMessageSend, error) {
return comp.Send(messages)
}
// SendMpNews 图文消息(mpnews)
func (comp *Client) SendMpNews(messages *request.RequestMessageSendMPNews) (*response.ResponseMessageSend, error) {
return comp.Send(messages)
}
// SendMarkdown markdown消息
func (comp *Client) SendMarkdown(messages *request.RequestMessageSendMarkdown) (*response.ResponseMessageSend, error) {
return comp.Send(messages)
}
// SendMiniProgramNotice 小程序通知消息
func (comp *Client) SendMiniProgramNotice(messages *request.RequestMessageSendMiniProgramNotice) (*response.ResponseMessageSend, error) {
return comp.Send(messages)
}
// SendTemplateCard 发送卡片模版
func (comp *Client) SendTemplateCard(messages *request.RequestMessageSendTemplateCard) (*response.ResponseMessageSend, error) {
return comp.Send(messages)
}
// 更新模版卡片消息
// https://work.weixin.qq.com/api/doc/90000/90135/94888
func (comp *Client) UpdateTemplateCard(card *power.HashMap) (*response.ResponseMessageSend, error) {
result := &response.ResponseMessageSend{}
if (*card)["agentid"] == nil || (*card)["agentid"].(int) <= 0 {
config := (*comp.App).GetConfig()
(*card)["agentid"] = config.GetInt("agent_id", 0)
}
_, err := comp.HttpPostJson("cgi-bin/message/update_template_card", card, nil, nil, result)
return result, err
}
// Recall 撤回应用消息
// https://open.work.weixin.qq.com/api/doc/90000/90135/94867
func (comp *Client) Recall(msgID string) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.HttpPostJson("cgi-bin/message/recall", power.StringMap{
"msgid": msgID,
}, nil, nil, result)
return result, err
}