forked from jpush/jpush-api-php-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportPayload.php
71 lines (61 loc) · 2.22 KB
/
ReportPayload.php
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
<?php
namespace JPush;
use InvalidArgumentException;
class ReportPayload {
private static $EFFECTIVE_TIME_UNIT = array('HOUR', 'DAY', 'MONTH');
private $client;
/**
* ReportPayload constructor.
* @param $client JPush
*/
public function __construct($client)
{
$this->client = $client;
}
public function getReceived($msgIds) {
$queryParams = '?msg_ids=';
if (is_array($msgIds) && !empty($msgIds)) {
$msgIdsStr = implode(',', $msgIds);
$queryParams .= $msgIdsStr;
} elseif (is_string($msgIds)) {
$queryParams .= $msgIds;
} else {
throw new InvalidArgumentException("Invalid msg_ids");
}
$url = $this->client->makeURL('report') . 'received/' . $queryParams;
return Http::get($this->client, $url);
}
public function getMessageStatus($msgId, $rids, $data = null) {
$url = $this->client->makeURL('report') . 'status/message';
$registrationIds = is_array($rids) ? $rids : array($rids);
$body = [
'msg_id' => $msgId,
'registration_ids' => $registrationIds
];
if (!is_null($data)) {
$body['data'] = $data;
}
return Http::post($this->client, $url, $body);
}
public function getMessages($msgIds) {
$queryParams = '?msg_ids=';
if (is_array($msgIds) && !empty($msgIds)) {
$msgIdsStr = implode(',', $msgIds);
$queryParams .= $msgIdsStr;
} elseif (is_string($msgIds)) {
$queryParams .= $msgIds;
} else {
throw new InvalidArgumentException("Invalid msg_ids");
}
$url = $this->client->makeURL('report') . 'messages/' .$queryParams;
return Http::get($this->client, $url);
}
public function getUsers($time_unit, $start, $duration) {
$time_unit = strtoupper($time_unit);
if (!in_array($time_unit, self::$EFFECTIVE_TIME_UNIT)) {
throw new InvalidArgumentException('Invalid time unit');
}
$url = $this->client->makeURL('report') . 'users/?time_unit=' . $time_unit . '&start=' . $start . '&duration=' . $duration;
return Http::get($this->client, $url);
}
}