-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
message.go
254 lines (209 loc) · 6.65 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
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
package datacube
import (
"context"
"fmt"
"github.com/donetkit/wechat/util"
)
const (
getUpstreamMsg = "https://api.weixin.qq.com/datacube/getupstreammsg"
getUpstreamMsgHour = "https://api.weixin.qq.com/datacube/getupstreammsghour"
getUpstreamMsgWeek = "https://api.weixin.qq.com/datacube/getupstreammsgweek"
getUpstreamMsgMonth = "https://api.weixin.qq.com/datacube/getupstreammsgmonth"
getUpstreamMsgDist = "https://api.weixin.qq.com/datacube/getupstreammsgdist"
getUpstreamMsgDistWeek = "https://api.weixin.qq.com/datacube/getupstreammsgdistweek"
getUpstreamMsgDistMonth = "https://api.weixin.qq.com/datacube/getupstreammsgdistmonth"
)
// ResUpstreamMsg 获取消息发送概况数据响应
type ResUpstreamMsg struct {
util.CommonError
List []struct {
RefDate string `json:"ref_date"`
MsgType int `json:"msg_type"`
MsgUser int `json:"msg_user"`
MsgCount int `json:"msg_count"`
} `json:"list"`
}
// ResUpstreamMsgHour 获取消息分送分时数据响应
type ResUpstreamMsgHour struct {
util.CommonError
List []struct {
RefDate string `json:"ref_date"`
RefHour int `json:"ref_hour"`
MsgType int `json:"msg_type"`
MsgUser int `json:"msg_user"`
MsgCount int `json:"msg_count"`
} `json:"list"`
}
// ResUpstreamMsgWeek 获取消息发送周数据响应
type ResUpstreamMsgWeek struct {
util.CommonError
List []struct {
RefDate string `json:"ref_date"`
MsgType int `json:"msg_type"`
MsgUser int `json:"msg_user"`
MsgCount int `json:"msg_count"`
} `json:"list"`
}
// ResUpstreamMsgMonth 获取消息发送月数据响应
type ResUpstreamMsgMonth struct {
util.CommonError
List []struct {
RefDate string `json:"ref_date"`
MsgType int `json:"msg_type"`
MsgUser int `json:"msg_user"`
MsgCount int `json:"msg_count"`
} `json:"list"`
}
// ResUpstreamMsgDist 获取消息发送分布数据响应
type ResUpstreamMsgDist struct {
util.CommonError
List []struct {
RefDate string `json:"ref_date"`
CountInterval int `json:"count_interval"`
MsgUser int `json:"msg_user"`
} `json:"list"`
}
// ResUpstreamMsgDistWeek 获取消息发送分布周数据响应
type ResUpstreamMsgDistWeek struct {
util.CommonError
List []struct {
RefDate string `json:"ref_date"`
CountInterval int `json:"count_interval"`
MsgUser int `json:"msg_user"`
} `json:"list"`
}
// ResUpstreamMsgDistMonth 获取消息发送分布月数据响应
type ResUpstreamMsgDistMonth struct {
util.CommonError
List []struct {
RefDate string `json:"ref_date"`
CountInterval int `json:"count_interval"`
MsgUser int `json:"msg_user"`
} `json:"list"`
}
// GetUpstreamMsg 获取消息发送概况数据
func (cube *DataCube) GetUpstreamMsg(ctx context.Context, s string, e string) (resUpstreamMsg ResUpstreamMsg, err error) {
accessToken, err := cube.GetAccessToken(ctx)
if err != nil {
return
}
uri := fmt.Sprintf("%s?access_token=%s", getUpstreamMsg, accessToken)
reqDate := &reqDate{
BeginDate: s,
EndDate: e,
}
response, err := util.PostJSONContext(ctx, uri, reqDate)
if err != nil {
return
}
err = util.DecodeWithError(response, &resUpstreamMsg, "GetUpstreamMsg")
return
}
// GetUpstreamMsgHour 获取消息分送分时数据
func (cube *DataCube) GetUpstreamMsgHour(ctx context.Context, s string, e string) (resUpstreamMsgHour ResUpstreamMsgHour, err error) {
accessToken, err := cube.GetAccessToken(ctx)
if err != nil {
return
}
uri := fmt.Sprintf("%s?access_token=%s", getUpstreamMsgHour, accessToken)
reqDate := &reqDate{
BeginDate: s,
EndDate: e,
}
response, err := util.PostJSONContext(ctx, uri, reqDate)
if err != nil {
return
}
err = util.DecodeWithError(response, &resUpstreamMsgHour, "GetUpstreamMsgHour")
return
}
// GetUpstreamMsgWeek 获取消息发送周数据
func (cube *DataCube) GetUpstreamMsgWeek(ctx context.Context, s string, e string) (resUpstreamMsgWeek ResUpstreamMsgWeek, err error) {
accessToken, err := cube.GetAccessToken(ctx)
if err != nil {
return
}
uri := fmt.Sprintf("%s?access_token=%s", getUpstreamMsgWeek, accessToken)
reqDate := &reqDate{
BeginDate: s,
EndDate: e,
}
response, err := util.PostJSONContext(ctx, uri, reqDate)
if err != nil {
return
}
err = util.DecodeWithError(response, &resUpstreamMsgWeek, "GetUpstreamMsgWeek")
return
}
// GetUpstreamMsgMonth 获取消息发送月数据
func (cube *DataCube) GetUpstreamMsgMonth(ctx context.Context, s string, e string) (resUpstreamMsgMonth ResUpstreamMsgMonth, err error) {
accessToken, err := cube.GetAccessToken(ctx)
if err != nil {
return
}
uri := fmt.Sprintf("%s?access_token=%s", getUpstreamMsgMonth, accessToken)
reqDate := &reqDate{
BeginDate: s,
EndDate: e,
}
response, err := util.PostJSONContext(ctx, uri, reqDate)
if err != nil {
return
}
err = util.DecodeWithError(response, &resUpstreamMsgMonth, "GetUpstreamMsgMonth")
return
}
// GetUpstreamMsgDist 获取消息发送分布数据
func (cube *DataCube) GetUpstreamMsgDist(ctx context.Context, s string, e string) (resUpstreamMsgDist ResUpstreamMsgDist, err error) {
accessToken, err := cube.GetAccessToken(ctx)
if err != nil {
return
}
uri := fmt.Sprintf("%s?access_token=%s", getUpstreamMsgDist, accessToken)
reqDate := &reqDate{
BeginDate: s,
EndDate: e,
}
response, err := util.PostJSONContext(ctx, uri, reqDate)
if err != nil {
return
}
err = util.DecodeWithError(response, &resUpstreamMsgDist, "GetUpstreamMsgDist")
return
}
// GetUpstreamMsgDistWeek 获取消息发送分布周数据
func (cube *DataCube) GetUpstreamMsgDistWeek(ctx context.Context, s string, e string) (resUpstreamMsgDistWeek ResUpstreamMsgDistWeek, err error) {
accessToken, err := cube.GetAccessToken(ctx)
if err != nil {
return
}
uri := fmt.Sprintf("%s?access_token=%s", getUpstreamMsgDistWeek, accessToken)
reqDate := &reqDate{
BeginDate: s,
EndDate: e,
}
response, err := util.PostJSONContext(ctx, uri, reqDate)
if err != nil {
return
}
err = util.DecodeWithError(response, &resUpstreamMsgDistWeek, "GetUpstreamMsgDistWeek")
return
}
// GetUpstreamMsgDistMonth 获取消息发送分布月数据
func (cube *DataCube) GetUpstreamMsgDistMonth(ctx context.Context, s string, e string) (resUpstreamMsgDistMonth ResUpstreamMsgDistMonth, err error) {
accessToken, err := cube.GetAccessToken(ctx)
if err != nil {
return
}
uri := fmt.Sprintf("%s?access_token=%s", getUpstreamMsgDistMonth, accessToken)
reqDate := &reqDate{
BeginDate: s,
EndDate: e,
}
response, err := util.PostJSONContext(ctx, uri, reqDate)
if err != nil {
return
}
err = util.DecodeWithError(response, &resUpstreamMsgDistMonth, "GetUpstreamMsgDistMonth")
return
}