-
Notifications
You must be signed in to change notification settings - Fork 14
/
moment.go
272 lines (250 loc) · 9.28 KB
/
moment.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package wework
import (
"github.com/go-laoji/wecom-go-sdk/v2/internal"
)
type MomentTask struct {
Text Text `json:"text,omitempty"`
Attachments []Attachments `json:"attachments" validate:"required_without=Text.Content"`
VisibleRange VisibleRange `json:"visible_range,omitempty"`
}
type Text struct {
Content string `json:"content"`
}
type Image struct {
MediaID string `json:"media_id" validate:"required"`
}
// Video 应用消息发关时title和description为可选项
// 朋友圈发送时只设置 media_id即可
type Video struct {
MediaID string `json:"media_id" validate:"required"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
}
type Link struct {
Title string `json:"title"`
URL string `json:"url" validate:"required"`
MediaID string `json:"media_id" validate:"required"`
}
type Attachments struct {
Msgtype string `json:"msgtype" validate:"required,oneof=image link video"`
Image *Image `json:"image,omitempty" validate:"required_without_all=Video Link"`
Video *Video `json:"video,omitempty" validate:"required_without_all=Image Link"`
Link *Link `json:"link,omitempty" validate:"required_without_all=Video Image"`
}
type SenderList struct {
UserList []string `json:"user_list"`
DepartmentList []int `json:"department_list"`
}
type ExternalContactList struct {
TagList []string `json:"tag_list"`
}
type VisibleRange struct {
SenderList SenderList `json:"sender_list,omitempty"`
ExternalContactList ExternalContactList `json:"external_contact_list,omitempty"`
}
type AddMomentTaskResponse struct {
internal.BizResponse
JobId string `json:"jobid"`
}
// AddMomentTask 创建发表任务
// 参考连接 https://open.work.weixin.qq.com/api/doc/90001/90143/95095#%E5%88%9B%E5%BB%BA%E5%8F%91%E8%A1%A8%E4%BB%BB%E5%8A%A1
func (ww *weWork) AddMomentTask(corpId uint, task MomentTask) (resp AddMomentTaskResponse) {
if ok := validate.Struct(task); ok != nil {
resp.ErrCode = 500
resp.ErrorMsg = ok.Error()
return
}
_, err := ww.getRequest(corpId).SetBody(task).SetResult(&resp).
Post("/cgi-bin/externalcontact/add_moment_task")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
type GetMomentTaskResultResponse struct {
internal.BizResponse
Status int `json:"status"`
Type string `json:"type"`
Result struct {
internal.BizResponse
MomentId string `json:"moment_id"`
InvalidSenderList struct {
UserList []string `json:"user_list"`
DepartmentList []int32 `json:"department_list"`
} `json:"invalid_sender_list"`
InvalidExternalContactList struct {
TagList []string `json:"tag_list"`
} `json:"invalid_external_contact_list"`
}
}
// GetMomentTaskResult 获取任务创建结果
// https://open.work.weixin.qq.com/api/doc/90001/90143/95095#%E8%8E%B7%E5%8F%96%E4%BB%BB%E5%8A%A1%E5%88%9B%E5%BB%BA%E7%BB%93%E6%9E%9C
func (ww *weWork) GetMomentTaskResult(corpId uint, jobId string) (resp GetMomentTaskResultResponse) {
_, err := ww.getRequest(corpId).SetQueryParam("jobid", jobId).SetResult(&resp).
Get("/cgi-bin/externalcontact/get_moment_task_result")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
type MomentListFilter struct {
StartTime int64 `json:"start_time" validate:"required"`
EndTime int64 `json:"end_time" validate:"required"`
Creator string `json:"creator,omitempty"`
FilterType int `json:"filter_type,omitempty" validate:"omitempty,oneof=0 1 2"`
Cursor string `json:"cursor"`
Limit int `json:"limit"`
}
type GetMomentListResponse struct {
internal.BizResponse
NextCursor string `json:"next_cursor"`
MomentList []MomentList `json:"moment_list"`
}
type Location struct {
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
Name string `json:"name"`
}
type MomentList struct {
MomentID string `json:"moment_id"`
Creator string `json:"creator"`
CreateTime string `json:"create_time"`
CreateType int `json:"create_type"`
VisibleType int `json:"visible_type"`
Text Text `json:"text"`
Image []Image `json:"image"`
Video Video `json:"video"`
Link Link `json:"link"`
Location Location `json:"location"`
}
// GetMomentList 获取企业全部的发表列表
// https://open.work.weixin.qq.com/api/doc/90001/90143/93443#%E8%8E%B7%E5%8F%96%E4%BC%81%E4%B8%9A%E5%85%A8%E9%83%A8%E7%9A%84%E5%8F%91%E8%A1%A8%E5%88%97%E8%A1%A8
func (ww *weWork) GetMomentList(corpId uint, filter MomentListFilter) (resp GetMomentListResponse) {
if ok := validate.Struct(filter); ok != nil {
resp.ErrCode = 500
resp.ErrorMsg = ok.Error()
return
}
_, err := ww.getRequest(corpId).SetBody(filter).SetResult(&resp).
Post("/cgi-bin/externalcontact/get_moment_list")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
type MomentTaskFilter struct {
MomentId string `json:"moment_id" validate:"required"`
Cursor string `json:"cursor"`
Limit int `json:"limit"`
}
type GetMomentTaskResponse struct {
internal.BizResponse
NextCursor string `json:"next_cursor"`
TaskList []struct {
UserId string `json:"userid"`
PublishStatus int `json:"publish_status"`
} `json:"task_list"`
}
// GetMomentTask 获取客户朋友圈企业发表的列表
// https://open.work.weixin.qq.com/api/doc/90001/90143/93443#%E8%8E%B7%E5%8F%96%E5%AE%A2%E6%88%B7%E6%9C%8B%E5%8F%8B%E5%9C%88%E4%BC%81%E4%B8%9A%E5%8F%91%E8%A1%A8%E7%9A%84%E5%88%97%E8%A1%A8
func (ww *weWork) GetMomentTask(corpId uint, filter MomentTaskFilter) (resp GetMomentTaskResponse) {
if ok := validate.Struct(filter); ok != nil {
resp.ErrCode = 500
resp.ErrorMsg = ok.Error()
}
_, err := ww.getRequest(corpId).SetBody(filter).SetResult(&resp).
Post("/cgi-bin/externalcontact/get_moment_task")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
type MomentCustomerFilter struct {
MomentId string `json:"moment_id" validate:"required"`
UserId string `json:"userid" validate:"required"`
Cursor string `json:"cursor,omitempty"`
Limit int `json:"limit,omitempty" validate:"omitempty,max=1000"`
}
type GetMomentCustomerListResponse struct {
internal.BizResponse
NextCursor string `json:"next_cursor"`
CustomerList []struct {
UserId string `json:"userid"`
ExternalUserId string `json:"external_userid"`
} `json:"customer_list"`
}
// GetMomentCustomerList 获取客户朋友圈发表时选择的可见范围
// https://open.work.weixin.qq.com/api/doc/90001/90143/93443#%E8%8E%B7%E5%8F%96%E5%AE%A2%E6%88%B7%E6%9C%8B%E5%8F%8B%E5%9C%88%E5%8F%91%E8%A1%A8%E6%97%B6%E9%80%89%E6%8B%A9%E7%9A%84%E5%8F%AF%E8%A7%81%E8%8C%83%E5%9B%B4
func (ww *weWork) GetMomentCustomerList(corpId uint, filter MomentCustomerFilter) (resp GetMomentCustomerListResponse) {
if ok := validate.Struct(filter); ok != nil {
resp.ErrCode = 500
resp.ErrorMsg = ok.Error()
}
_, err := ww.getRequest(corpId).SetBody(filter).SetResult(&resp).
Post("/cgi-bin/externalcontact/get_moment_customer_list")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
type GetMomentSendResultResponse struct {
internal.BizResponse
NextCursor string `json:"next_cursor"`
CustomerList []struct {
ExternalUserId string `json:"external_userid"`
} `json:"customer_list"`
}
// GetMomentSendResult 获取客户朋友圈发表后的可见客户列表
// https://open.work.weixin.qq.com/api/doc/90001/90143/93443#%E8%8E%B7%E5%8F%96%E5%AE%A2%E6%88%B7%E6%9C%8B%E5%8F%8B%E5%9C%88%E5%8F%91%E8%A1%A8%E5%90%8E%E7%9A%84%E5%8F%AF%E8%A7%81%E5%AE%A2%E6%88%B7%E5%88%97%E8%A1%A8
func (ww *weWork) GetMomentSendResult(corpId uint, filter MomentCustomerFilter) (resp GetMomentSendResultResponse) {
if ok := validate.Struct(filter); ok != nil {
resp.ErrCode = 500
resp.ErrorMsg = ok.Error()
}
_, err := ww.getRequest(corpId).SetBody(filter).SetResult(&resp).
Post("/cgi-bin/externalcontact/get_moment_send_result")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
type GetMomentCommentsResponse struct {
internal.BizResponse
CommentList []struct {
ExternalUserId string `json:"external_userid"`
CreateTime int `json:"create_time"`
} `json:"comment_list"`
LikeList []struct {
ExternalUserId string `json:"external_userid"`
CreateTime int `json:"create_time"`
} `json:"like_list"`
}
// GetMomentComments 获取客户朋友圈的互动数据
// https://open.work.weixin.qq.com/api/doc/90001/90143/93443#%E8%8E%B7%E5%8F%96%E5%AE%A2%E6%88%B7%E6%9C%8B%E5%8F%8B%E5%9C%88%E7%9A%84%E4%BA%92%E5%8A%A8%E6%95%B0%E6%8D%AE
func (ww *weWork) GetMomentComments(corpId uint, momentId string, userId string) (resp GetMomentCommentsResponse) {
p := H{"userid": userId, "moment_id": momentId}
_, err := ww.getRequest(corpId).SetBody(p).SetResult(&resp).
Post("/cgi-bin/externalcontact/get_moment_comments")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
// CancelMomentTask 停止发表企业朋友圈
// https://developer.work.weixin.qq.com/document/path/97612
func (ww *weWork) CancelMomentTask(corpId uint, momentId string) (resp internal.BizResponse) {
_, err := ww.getRequest(corpId).SetQueryParam("moment_id", momentId).SetResult(&resp).
Get("/cgi-bin/externalcontact/cancel_moment_task")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}