|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the overtrue/wechat. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) overtrue <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Stats.php. |
|
14
|
|
|
* |
|
15
|
|
|
* @author overtrue <[email protected]> |
|
16
|
|
|
* @copyright 2015 overtrue <[email protected]> |
|
17
|
|
|
* |
|
18
|
|
|
* @link https://github.com/overtrue |
|
19
|
|
|
* @link http://overtrue.me |
|
20
|
|
|
*/ |
|
21
|
|
|
namespace EasyWeChat\Stats; |
|
22
|
|
|
|
|
23
|
|
|
use EasyWeChat\Core\AbstractAPI; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class stats. |
|
27
|
|
|
*/ |
|
28
|
|
|
class Stats extends AbstractAPI |
|
29
|
|
|
{ |
|
30
|
|
|
// 获取用户增减数据 |
|
31
|
|
|
const API_USER_SUMMARY = 'https://api.weixin.qq.com/datacube/getusersummary'; |
|
32
|
|
|
// 获取累计用户数据 |
|
33
|
|
|
const API_USER_CUMULATE = 'https://api.weixin.qq.com/datacube/getusercumulate'; |
|
34
|
|
|
// 获取图文群发每日数据 |
|
35
|
|
|
const API_ARTICLE_SUMMARY = 'https://api.weixin.qq.com/datacube/getarticlesummary'; |
|
36
|
|
|
// 获取图文群发总数据 |
|
37
|
|
|
const API_ARTICLE_TOTAL = 'https://api.weixin.qq.com/datacube/getarticletotal'; |
|
38
|
|
|
// 获取图文统计数据 |
|
39
|
|
|
const API_USER_READ_SUMMARY = 'https://api.weixin.qq.com/datacube/getuserread'; |
|
40
|
|
|
// 获取图文统计分时数据 |
|
41
|
|
|
const API_USER_READ_HOURLY = 'https://api.weixin.qq.com/datacube/getuserreadhour'; |
|
42
|
|
|
// 获取图文分享转发数据 |
|
43
|
|
|
const API_USER_SHARE_SUMMARY = 'https://api.weixin.qq.com/datacube/getusershare'; |
|
44
|
|
|
// 获取图文分享转发分时数据 |
|
45
|
|
|
const API_USER_SHARE_HOURLY = 'https://api.weixin.qq.com/datacube/getusersharehour'; |
|
46
|
|
|
// 获取消息发送概况数据 |
|
47
|
|
|
const API_UPSTREAM_MSG_SUMMARY = 'https://api.weixin.qq.com/datacube/getupstreammsg'; |
|
48
|
|
|
// 获取消息分送分时数据 |
|
49
|
|
|
const API_UPSTREAM_MSG_HOURLY = 'https://api.weixin.qq.com/datacube/getupstreammsghour'; |
|
50
|
|
|
// 获取消息发送周数据 |
|
51
|
|
|
const API_UPSTREAM_MSG_WEEKLY = 'https://api.weixin.qq.com/datacube/getupstreammsgweek'; |
|
52
|
|
|
// 获取消息发送月数据 |
|
53
|
|
|
const API_UPSTREAM_MSG_MONTHLY = 'https://api.weixin.qq.com/datacube/getupstreammsgmonth'; |
|
54
|
|
|
// 获取消息发送分布数据 |
|
55
|
|
|
const API_UPSTREAM_MSG_DIST_SUMMARY = 'https://api.weixin.qq.com/datacube/getupstreammsgdist'; |
|
56
|
|
|
// 获取消息发送分布周数据 |
|
57
|
|
|
const API_UPSTREAM_MSG_DIST_WEEKLY = 'https://api.weixin.qq.com/datacube/getupstreammsgdistweek'; |
|
58
|
|
|
// 获取消息发送分布月数据 |
|
59
|
|
|
const API_UPSTREAM_MSG_DIST_MONTHLY = 'https://api.weixin.qq.com/datacube/getupstreammsgdistmonth?'; |
|
60
|
|
|
// 获取接口分析数据 |
|
61
|
|
|
const API_INTERFACE_SUMMARY = 'https://api.weixin.qq.com/datacube/getinterfacesummary'; |
|
62
|
|
|
// 获取接口分析分时数据 |
|
63
|
|
|
const API_INTERFACE_SUMMARY_HOURLY = 'https://api.weixin.qq.com/datacube/getinterfacesummaryhour'; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* 获取用户增减数据. |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $from |
|
69
|
|
|
* @param string $to |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
1 |
|
public function userSummary($from, $to) |
|
74
|
|
|
{ |
|
75
|
1 |
|
return $this->query(self::API_USER_SUMMARY, $from, $to); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* 获取累计用户数据. |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $from |
|
82
|
|
|
* @param string $to |
|
83
|
|
|
* |
|
84
|
|
|
* @return array |
|
85
|
|
|
*/ |
|
86
|
1 |
|
public function userCumulate($from, $to) |
|
87
|
|
|
{ |
|
88
|
1 |
|
return $this->query(self::API_USER_CUMULATE, $from, $to); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* 获取图文群发每日数据. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $from |
|
95
|
|
|
* @param string $to |
|
96
|
|
|
* |
|
97
|
|
|
* @return array |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function articleSummary($from, $to) |
|
100
|
|
|
{ |
|
101
|
1 |
|
return $this->query(self::API_ARTICLE_SUMMARY, $from, $to); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* 获取图文群发总数据. |
|
106
|
|
|
* |
|
107
|
|
|
* @param string $from |
|
108
|
|
|
* @param string $to |
|
109
|
|
|
* |
|
110
|
|
|
* @return array |
|
111
|
|
|
*/ |
|
112
|
1 |
|
public function articleTotal($from, $to) |
|
113
|
|
|
{ |
|
114
|
1 |
|
return $this->query(self::API_ARTICLE_TOTAL, $from, $to); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* 获取图文统计数据. |
|
119
|
|
|
* |
|
120
|
|
|
* @param string $from |
|
121
|
|
|
* @param string $to |
|
122
|
|
|
* |
|
123
|
|
|
* @return array |
|
124
|
|
|
*/ |
|
125
|
1 |
|
public function userReadSummary($from, $to) |
|
126
|
|
|
{ |
|
127
|
1 |
|
return $this->query(self::API_USER_READ_SUMMARY, $from, $to); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* 获取图文统计分时数据. |
|
132
|
|
|
* |
|
133
|
|
|
* @param string $from |
|
134
|
|
|
* @param string $to |
|
135
|
|
|
* |
|
136
|
|
|
* @return array |
|
137
|
|
|
*/ |
|
138
|
1 |
|
public function userReadHourly($from, $to) |
|
139
|
|
|
{ |
|
140
|
1 |
|
return $this->query(self::API_USER_READ_HOURLY, $from, $to); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* 获取图文分享转发数据. |
|
145
|
|
|
* |
|
146
|
|
|
* @param string $from |
|
147
|
|
|
* @param string $to |
|
148
|
|
|
* |
|
149
|
|
|
* @return array |
|
150
|
|
|
*/ |
|
151
|
1 |
|
public function userShareSummary($from, $to) |
|
152
|
|
|
{ |
|
153
|
1 |
|
return $this->query(self::API_USER_SHARE_SUMMARY, $from, $to); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* 获取图文分享转发分时数据. |
|
158
|
|
|
* |
|
159
|
|
|
* @param string $from |
|
160
|
|
|
* @param string $to |
|
161
|
|
|
* |
|
162
|
|
|
* @return array |
|
163
|
|
|
*/ |
|
164
|
1 |
|
public function userShareHourly($from, $to) |
|
165
|
|
|
{ |
|
166
|
1 |
|
return $this->query(self::API_USER_SHARE_HOURLY, $from, $to); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* 获取消息发送概况数据. |
|
171
|
|
|
* |
|
172
|
|
|
* @param string $from |
|
173
|
|
|
* @param string $to |
|
174
|
|
|
* |
|
175
|
|
|
* @return array |
|
176
|
|
|
*/ |
|
177
|
1 |
|
public function upstreamMessageSummary($from, $to) |
|
178
|
|
|
{ |
|
179
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_SUMMARY, $from, $to); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* 获取消息分送分时数据. |
|
184
|
|
|
* |
|
185
|
|
|
* @param string $from |
|
186
|
|
|
* @param string $to |
|
187
|
|
|
* |
|
188
|
|
|
* @return array |
|
189
|
|
|
*/ |
|
190
|
1 |
|
public function upstreamMessageHourly($from, $to) |
|
191
|
|
|
{ |
|
192
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_HOURLY, $from, $to); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* 获取消息发送周数据. |
|
197
|
|
|
* |
|
198
|
|
|
* @param string $from |
|
199
|
|
|
* @param string $to |
|
200
|
|
|
* |
|
201
|
|
|
* @return array |
|
202
|
|
|
*/ |
|
203
|
1 |
|
public function upstreamMessageWeekly($from, $to) |
|
204
|
|
|
{ |
|
205
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_WEEKLY, $from, $to); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* 获取消息发送月数据. |
|
210
|
|
|
* |
|
211
|
|
|
* @param string $from |
|
212
|
|
|
* @param string $to |
|
213
|
|
|
* |
|
214
|
|
|
* @return array |
|
215
|
|
|
*/ |
|
216
|
1 |
|
public function upstreamMessageMonthly($from, $to) |
|
217
|
|
|
{ |
|
218
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_MONTHLY, $from, $to); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* 获取消息发送分布数据. |
|
223
|
|
|
* |
|
224
|
|
|
* @param string $from |
|
225
|
|
|
* @param string $to |
|
226
|
|
|
* |
|
227
|
|
|
* @return array |
|
228
|
|
|
*/ |
|
229
|
1 |
|
public function upstreamMessageDistSummary($from, $to) |
|
230
|
|
|
{ |
|
231
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_DIST_SUMMARY, $from, $to); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* 获取消息发送分布周数据. |
|
236
|
|
|
* |
|
237
|
|
|
* @param string $from |
|
238
|
|
|
* @param string $to |
|
239
|
|
|
* |
|
240
|
|
|
* @return array |
|
241
|
|
|
*/ |
|
242
|
1 |
|
public function upstreamMessageDistWeekly($from, $to) |
|
243
|
|
|
{ |
|
244
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_DIST_WEEKLY, $from, $to); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* 获取消息发送分布月数据. |
|
249
|
|
|
* |
|
250
|
|
|
* @param string $from |
|
251
|
|
|
* @param string $to |
|
252
|
|
|
* |
|
253
|
|
|
* @return array |
|
254
|
|
|
*/ |
|
255
|
1 |
|
public function upstreamMessageDistMonthly($from, $to) |
|
256
|
|
|
{ |
|
257
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_DIST_MONTHLY, $from, $to); |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* 获取接口分析数据. |
|
262
|
|
|
* |
|
263
|
|
|
* @param string $from |
|
264
|
|
|
* @param string $to |
|
265
|
|
|
* |
|
266
|
|
|
* @return array |
|
267
|
|
|
*/ |
|
268
|
1 |
|
public function interfaceSummary($from, $to) |
|
269
|
|
|
{ |
|
270
|
1 |
|
return $this->query(self::API_INTERFACE_SUMMARY, $from, $to); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
/** |
|
274
|
|
|
* 获取接口分析分时数据. |
|
275
|
|
|
* |
|
276
|
|
|
* @param string $from |
|
277
|
|
|
* @param string $to |
|
278
|
|
|
* |
|
279
|
|
|
* @return array |
|
280
|
|
|
*/ |
|
281
|
1 |
|
public function interfaceSummaryHourly($from, $to) |
|
282
|
|
|
{ |
|
283
|
1 |
|
return $this->query(self::API_INTERFACE_SUMMARY_HOURLY, $from, $to); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* 查询数据. |
|
288
|
|
|
* |
|
289
|
|
|
* @param string $api |
|
290
|
|
|
* @param string $from |
|
291
|
|
|
* @param string $to |
|
292
|
|
|
* |
|
293
|
|
|
* @return array |
|
294
|
|
|
*/ |
|
295
|
17 |
|
protected function query($api, $from, $to) |
|
296
|
|
|
{ |
|
297
|
|
|
$params = [ |
|
298
|
17 |
|
'begin_date' => $from, |
|
299
|
17 |
|
'end_date' => $to, |
|
300
|
17 |
|
]; |
|
301
|
|
|
|
|
302
|
17 |
|
return $this->parseJSON('json', [$api, $params]); |
|
303
|
|
|
} |
|
304
|
|
|
} |
|
305
|
|
|
|