forked from chanxuehong/wechat
-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_upstream_msg.go
229 lines (190 loc) · 5.86 KB
/
client_upstream_msg.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
// @description wechat 是腾讯微信公众平台 api 的 golang 语言封装
// @link https://github.com/chanxuehong/wechat for the canonical source repository
// @license https://github.com/chanxuehong/wechat/blob/master/LICENSE
// @authors chanxuehong(chanxuehong@gmail.com)
package datacube
import (
"errors"
"github.com/chanxuehong/wechat/mp"
)
// 消息发送概况数据
type UpstreamMsgData struct {
RefDate string `json:"ref_date"` // 数据的日期, YYYY-MM-DD 格式
UserSource int `json:"user_source"` // 返回的 json 有这个字段, 文档中没有, 都是 0 值, 可能没有实际意义!!!
// 消息类型, 代表含义如下:
// 1代表文字
// 2代表图片
// 3代表语音
// 4代表视频
// 6代表第三方应用消息(链接消息)
MsgType int `json:"msg_type"`
MsgUser int `json:"msg_user"` // 上行发送了(向公众号发送了)消息的用户数
MsgCount int `json:"msg_count"` // 上行发送了消息的消息总数
}
// 获取消息发送概况数据.
func (clt *Client) GetUpstreamMsg(req *Request) (list []UpstreamMsgData, err error) {
if req == nil {
err = errors.New("nil Request")
return
}
var result struct {
mp.Error
List []UpstreamMsgData `json:"list"`
}
incompleteURL := "https://api.weixin.qq.com/datacube/getupstreammsg?access_token="
if err = ((*mp.Client)(clt)).PostJSON(incompleteURL, req, &result); err != nil {
return
}
if result.ErrCode != mp.ErrCodeOK {
err = &result.Error
return
}
list = result.List
return
}
// 消息分送分时数据
type UpstreamMsgHourData struct {
RefHour int `json:"ref_hour"` // 数据的小时, 包括从000到2300, 分别代表的是[000,100)到[2300,2400), 即每日的第1小时和最后1小时
UpstreamMsgData
}
// 获取消息分送分时数据.
func (clt *Client) GetUpstreamMsgHour(req *Request) (list []UpstreamMsgHourData, err error) {
if req == nil {
err = errors.New("nil Request")
return
}
var result struct {
mp.Error
List []UpstreamMsgHourData `json:"list"`
}
incompleteURL := "https://api.weixin.qq.com/datacube/getupstreammsghour?access_token="
if err = ((*mp.Client)(clt)).PostJSON(incompleteURL, req, &result); err != nil {
return
}
if result.ErrCode != mp.ErrCodeOK {
err = &result.Error
return
}
list = result.List
return
}
// 消息发送周数据
type UpstreamMsgWeekData UpstreamMsgData
// 获取消息发送周数据.
func (clt *Client) GetUpstreamMsgWeek(req *Request) (list []UpstreamMsgWeekData, err error) {
if req == nil {
err = errors.New("nil Request")
return
}
var result struct {
mp.Error
List []UpstreamMsgWeekData `json:"list"`
}
incompleteURL := "https://api.weixin.qq.com/datacube/getupstreammsgweek?access_token="
if err = ((*mp.Client)(clt)).PostJSON(incompleteURL, req, &result); err != nil {
return
}
if result.ErrCode != mp.ErrCodeOK {
err = &result.Error
return
}
list = result.List
return
}
// 消息发送月数据
type UpstreamMsgMonthData UpstreamMsgData
// 获取消息发送月数据.
func (clt *Client) GetUpstreamMsgMonth(req *Request) (list []UpstreamMsgMonthData, err error) {
if req == nil {
err = errors.New("nil Request")
return
}
var result struct {
mp.Error
List []UpstreamMsgMonthData `json:"list"`
}
incompleteURL := "https://api.weixin.qq.com/datacube/getupstreammsgmonth?access_token="
if err = ((*mp.Client)(clt)).PostJSON(incompleteURL, req, &result); err != nil {
return
}
if result.ErrCode != mp.ErrCodeOK {
err = &result.Error
return
}
list = result.List
return
}
// 消息发送分布数据
type UpstreamMsgDistData struct {
RefDate string `json:"ref_date"` // 数据的日期, YYYY-MM-DD 格式
UserSource int `json:"user_source"` // 返回的 json 有这个字段, 文档中没有, 都是 0 值, 可能没有实际意义!!!
CountInterval int `json:"count_interval"` // 当日发送消息量分布的区间, 0代表 "0", 1代表"1-5", 2代表"6-10", 3代表"10次以上"
MsgUser int `json:"msg_user"` // 上行发送了(向公众号发送了)消息的用户数
}
// 获取消息发送分布数据.
func (clt *Client) GetUpstreamMsgDist(req *Request) (list []UpstreamMsgDistData, err error) {
if req == nil {
err = errors.New("nil Request")
return
}
var result struct {
mp.Error
List []UpstreamMsgDistData `json:"list"`
}
incompleteURL := "https://api.weixin.qq.com/datacube/getupstreammsgdist?access_token="
if err = ((*mp.Client)(clt)).PostJSON(incompleteURL, req, &result); err != nil {
return
}
if result.ErrCode != mp.ErrCodeOK {
err = &result.Error
return
}
list = result.List
return
}
// 消息发送分布周数据
type UpstreamMsgDistWeekData UpstreamMsgDistData
// 获取消息发送分布周数据.
func (clt *Client) GetUpstreamMsgDistWeek(req *Request) (list []UpstreamMsgDistWeekData, err error) {
if req == nil {
err = errors.New("nil Request")
return
}
var result struct {
mp.Error
List []UpstreamMsgDistWeekData `json:"list"`
}
incompleteURL := "https://api.weixin.qq.com/datacube/getupstreammsgdistweek?access_token="
if err = ((*mp.Client)(clt)).PostJSON(incompleteURL, req, &result); err != nil {
return
}
if result.ErrCode != mp.ErrCodeOK {
err = &result.Error
return
}
list = result.List
return
}
// 消息发送分布月数据
type UpstreamMsgDistMonthData UpstreamMsgDistData
// 获取消息发送分布月数据.
func (clt *Client) GetUpstreamMsgDistMonth(req *Request) (list []UpstreamMsgDistMonthData, err error) {
if req == nil {
err = errors.New("nil Request")
return
}
var result struct {
mp.Error
List []UpstreamMsgDistMonthData `json:"list"`
}
incompleteURL := "https://api.weixin.qq.com/datacube/getupstreammsgdistmonth?access_token="
if err = ((*mp.Client)(clt)).PostJSON(incompleteURL, req, &result); err != nil {
return
}
if result.ErrCode != mp.ErrCodeOK {
err = &result.Error
return
}
list = result.List
return
}