forked from jpush/jpush-api-php-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.php
71 lines (64 loc) · 2.58 KB
/
Client.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 Client {
private $appKey;
private $masterSecret;
private $retryTimes;
private $logFile;
private $zone;
private static $zones = [
'DEFAULT' => [
'push' => 'https://api.jpush.cn/v3/',
'report' => 'https://report.jpush.cn/v3/',
'device' => 'https://device.jpush.cn/v3/devices/',
'alias' => 'https://device.jpush.cn/v3/aliases/',
'tag' => 'https://device.jpush.cn/v3/tags/',
'schedule' => 'https://api.jpush.cn/v3/schedules/'
],
'BJ' => [
'push' => 'https://bjapi.push.jiguang.cn/v3/',
'report' => 'https://bjapi.push.jiguang.cn/v3/report/',
'device' => 'https://bjapi.push.jiguang.cn/v3/device/',
'alias' => 'https://bjapi.push.jiguang.cn/v3/device/aliases/',
'tag' => 'https://bjapi.push.jiguang.cn/v3/device/tags/',
'schedules' => 'https://bjapi.push.jiguang.cn/v3/push/schedules/'
]
];
public function __construct($appKey, $masterSecret, $logFile=Config::DEFAULT_LOG_FILE, $retryTimes=Config::DEFAULT_MAX_RETRY_TIMES, $zone = null) {
if (!is_string($appKey) || !is_string($masterSecret)) {
throw new InvalidArgumentException("Invalid appKey or masterSecret");
}
$this->appKey = $appKey;
$this->masterSecret = $masterSecret;
if (!is_null($retryTimes)) {
$this->retryTimes = $retryTimes;
} else {
$this->retryTimes = 1;
}
$this->logFile = $logFile;
if (!is_null($zone) && in_array(strtoupper($zone), array_keys(self::$zones))) {
$this->zone = strtoupper($zone);
} else {
$this->zone= null;
}
}
public function push() { return new PushPayload($this); }
public function report() { return new ReportPayload($this); }
public function device() { return new DevicePayload($this); }
public function schedule() { return new SchedulePayload($this);}
public function getAuthStr() { return $this->appKey . ":" . $this->masterSecret; }
public function getRetryTimes() { return $this->retryTimes; }
public function getLogFile() { return $this->logFile; }
public function is_group() {
$str = substr($this->appKey, 0, 6);
return $str === 'group-';
}
public function makeURL($key) {
if (is_null($this->zone)) {
return self::$zones['DEFAULT'][$key];
} else {
return self::$zones[$this->zone][$key];
}
}
}