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
|
|
|
const API_CARD_SUMMARY = 'https://api.weixin.qq.com/datacube/getcardbizuininfo'; |
66
|
|
|
// 获取免费券数据接口 |
67
|
|
|
const API_FREE_CARD_SUMMARY = 'https://api.weixin.qq.com/datacube/getcardcardinfo'; |
68
|
|
|
// 拉取会员卡数据接口 |
69
|
|
|
const API_MEMBER_CARD_SUMMARY = 'https://api.weixin.qq.com/datacube/getcardmembercardinfo'; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* 获取用户增减数据. |
73
|
|
|
* |
74
|
|
|
* @param string $from |
75
|
|
|
* @param string $to |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
1 |
|
public function userSummary($from, $to) |
80
|
|
|
{ |
81
|
1 |
|
return $this->query(self::API_USER_SUMMARY, $from, $to); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* 获取累计用户数据. |
86
|
|
|
* |
87
|
|
|
* @param string $from |
88
|
|
|
* @param string $to |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
1 |
|
public function userCumulate($from, $to) |
93
|
|
|
{ |
94
|
1 |
|
return $this->query(self::API_USER_CUMULATE, $from, $to); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* 获取图文群发每日数据. |
99
|
|
|
* |
100
|
|
|
* @param string $from |
101
|
|
|
* @param string $to |
102
|
|
|
* |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
1 |
|
public function articleSummary($from, $to) |
106
|
|
|
{ |
107
|
1 |
|
return $this->query(self::API_ARTICLE_SUMMARY, $from, $to); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* 获取图文群发总数据. |
112
|
|
|
* |
113
|
|
|
* @param string $from |
114
|
|
|
* @param string $to |
115
|
|
|
* |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
1 |
|
public function articleTotal($from, $to) |
119
|
|
|
{ |
120
|
1 |
|
return $this->query(self::API_ARTICLE_TOTAL, $from, $to); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* 获取图文统计数据. |
125
|
|
|
* |
126
|
|
|
* @param string $from |
127
|
|
|
* @param string $to |
128
|
|
|
* |
129
|
|
|
* @return array |
130
|
|
|
*/ |
131
|
1 |
|
public function userReadSummary($from, $to) |
132
|
|
|
{ |
133
|
1 |
|
return $this->query(self::API_USER_READ_SUMMARY, $from, $to); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* 获取图文统计分时数据. |
138
|
|
|
* |
139
|
|
|
* @param string $from |
140
|
|
|
* @param string $to |
141
|
|
|
* |
142
|
|
|
* @return array |
143
|
|
|
*/ |
144
|
1 |
|
public function userReadHourly($from, $to) |
145
|
|
|
{ |
146
|
1 |
|
return $this->query(self::API_USER_READ_HOURLY, $from, $to); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* 获取图文分享转发数据. |
151
|
|
|
* |
152
|
|
|
* @param string $from |
153
|
|
|
* @param string $to |
154
|
|
|
* |
155
|
|
|
* @return array |
156
|
|
|
*/ |
157
|
1 |
|
public function userShareSummary($from, $to) |
158
|
|
|
{ |
159
|
1 |
|
return $this->query(self::API_USER_SHARE_SUMMARY, $from, $to); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* 获取图文分享转发分时数据. |
164
|
|
|
* |
165
|
|
|
* @param string $from |
166
|
|
|
* @param string $to |
167
|
|
|
* |
168
|
|
|
* @return array |
169
|
|
|
*/ |
170
|
1 |
|
public function userShareHourly($from, $to) |
171
|
|
|
{ |
172
|
1 |
|
return $this->query(self::API_USER_SHARE_HOURLY, $from, $to); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* 获取消息发送概况数据. |
177
|
|
|
* |
178
|
|
|
* @param string $from |
179
|
|
|
* @param string $to |
180
|
|
|
* |
181
|
|
|
* @return array |
182
|
|
|
*/ |
183
|
1 |
|
public function upstreamMessageSummary($from, $to) |
184
|
|
|
{ |
185
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_SUMMARY, $from, $to); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* 获取消息分送分时数据. |
190
|
|
|
* |
191
|
|
|
* @param string $from |
192
|
|
|
* @param string $to |
193
|
|
|
* |
194
|
|
|
* @return array |
195
|
|
|
*/ |
196
|
1 |
|
public function upstreamMessageHourly($from, $to) |
197
|
|
|
{ |
198
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_HOURLY, $from, $to); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* 获取消息发送周数据. |
203
|
|
|
* |
204
|
|
|
* @param string $from |
205
|
|
|
* @param string $to |
206
|
|
|
* |
207
|
|
|
* @return array |
208
|
|
|
*/ |
209
|
1 |
|
public function upstreamMessageWeekly($from, $to) |
210
|
|
|
{ |
211
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_WEEKLY, $from, $to); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* 获取消息发送月数据. |
216
|
|
|
* |
217
|
|
|
* @param string $from |
218
|
|
|
* @param string $to |
219
|
|
|
* |
220
|
|
|
* @return array |
221
|
|
|
*/ |
222
|
1 |
|
public function upstreamMessageMonthly($from, $to) |
223
|
|
|
{ |
224
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_MONTHLY, $from, $to); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* 获取消息发送分布数据. |
229
|
|
|
* |
230
|
|
|
* @param string $from |
231
|
|
|
* @param string $to |
232
|
|
|
* |
233
|
|
|
* @return array |
234
|
|
|
*/ |
235
|
1 |
|
public function upstreamMessageDistSummary($from, $to) |
236
|
|
|
{ |
237
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_DIST_SUMMARY, $from, $to); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* 获取消息发送分布周数据. |
242
|
|
|
* |
243
|
|
|
* @param string $from |
244
|
|
|
* @param string $to |
245
|
|
|
* |
246
|
|
|
* @return array |
247
|
|
|
*/ |
248
|
1 |
|
public function upstreamMessageDistWeekly($from, $to) |
249
|
|
|
{ |
250
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_DIST_WEEKLY, $from, $to); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* 获取消息发送分布月数据. |
255
|
|
|
* |
256
|
|
|
* @param string $from |
257
|
|
|
* @param string $to |
258
|
|
|
* |
259
|
|
|
* @return array |
260
|
|
|
*/ |
261
|
1 |
|
public function upstreamMessageDistMonthly($from, $to) |
262
|
|
|
{ |
263
|
1 |
|
return $this->query(self::API_UPSTREAM_MSG_DIST_MONTHLY, $from, $to); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* 获取接口分析数据. |
268
|
|
|
* |
269
|
|
|
* @param string $from |
270
|
|
|
* @param string $to |
271
|
|
|
* |
272
|
|
|
* @return array |
273
|
|
|
*/ |
274
|
1 |
|
public function interfaceSummary($from, $to) |
275
|
|
|
{ |
276
|
1 |
|
return $this->query(self::API_INTERFACE_SUMMARY, $from, $to); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* 获取接口分析分时数据. |
281
|
|
|
* |
282
|
|
|
* @param string $from |
283
|
|
|
* @param string $to |
284
|
|
|
* |
285
|
|
|
* @return array |
286
|
|
|
*/ |
287
|
1 |
|
public function interfaceSummaryHourly($from, $to) |
288
|
|
|
{ |
289
|
1 |
|
return $this->query(self::API_INTERFACE_SUMMARY_HOURLY, $from, $to); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* 拉取卡券概况数据接口. |
294
|
|
|
* |
295
|
|
|
* @param string $from |
296
|
|
|
* @param string $to |
297
|
|
|
* @param int $condSource |
298
|
|
|
* |
299
|
|
|
* @return array |
300
|
|
|
*/ |
301
|
1 |
View Code Duplication |
public function cardSummary($from, $to, $condSource = 0) |
302
|
|
|
{ |
303
|
|
|
$ext = [ |
304
|
1 |
|
'cond_source' => intval($condSource), |
305
|
1 |
|
]; |
306
|
|
|
|
307
|
1 |
|
return $this->query(self::API_CARD_SUMMARY, $from, $to, $ext); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* 获取免费券数据接口. |
312
|
|
|
* |
313
|
|
|
* @param string $from |
314
|
|
|
* @param string $to |
315
|
|
|
* @param int $condSource |
316
|
|
|
* @param string $cardId |
317
|
|
|
* |
318
|
|
|
* @return array |
319
|
|
|
*/ |
320
|
1 |
View Code Duplication |
public function freeCardSummary($from, $to, $condSource = 0, $cardId = '') |
321
|
|
|
{ |
322
|
|
|
$ext = [ |
323
|
1 |
|
'cond_source' => intval($condSource), |
324
|
1 |
|
'card_id' => $cardId, |
325
|
1 |
|
]; |
326
|
|
|
|
327
|
1 |
|
return $this->query(self::API_FREE_CARD_SUMMARY, $from, $to, $ext); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* 拉取会员卡数据接口. |
332
|
|
|
* |
333
|
|
|
* @param string $from |
334
|
|
|
* @param string $to |
335
|
|
|
* @param int $condSource |
336
|
|
|
* |
337
|
|
|
* @return array |
338
|
|
|
*/ |
339
|
1 |
View Code Duplication |
public function memberCardSummary($from, $to, $condSource = 0) |
340
|
|
|
{ |
341
|
|
|
$ext = [ |
342
|
1 |
|
'cond_source' => intval($condSource), |
343
|
1 |
|
]; |
344
|
|
|
|
345
|
1 |
|
return $this->query(self::API_MEMBER_CARD_SUMMARY, $from, $to, $ext); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* 查询数据. |
350
|
|
|
* |
351
|
|
|
* @param string $api |
352
|
|
|
* @param string $from |
353
|
|
|
* @param string $to |
354
|
|
|
* |
355
|
|
|
* @return array |
356
|
|
|
*/ |
357
|
20 |
|
protected function query($api, $from, $to, array $ext = []) |
358
|
|
|
{ |
359
|
|
|
$params = [ |
360
|
20 |
|
'begin_date' => $from, |
361
|
20 |
|
'end_date' => $to, |
362
|
20 |
|
]; |
363
|
|
|
|
364
|
20 |
|
if (!empty($ext)) { |
365
|
3 |
|
$params = array_merge($params, $ext); |
366
|
3 |
|
} |
367
|
|
|
|
368
|
20 |
|
return $this->parseJSON('json', [$api, $params]); |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
|