Skip to content

Commit ebb191e

Browse files
committed
update custom,用户可自定义最外层参数
1 parent 8f2b78c commit ebb191e

File tree

2 files changed

+53
-23
lines changed

2 files changed

+53
-23
lines changed

examples/push_example.php

+35-19
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@
66
use JPush\Client as JPush;
77

88
// 这里填写appKey,masterSecret以及registration_id
9-
$app_key = 'your AppKey';
10-
$master_secret = 'your MasterSecret';
9+
$app_key = 'e5c0d34f58732cf09b2d4d74';
10+
$master_secret = '4cdda6d3c8b029941dbc5cb3';
1111
$registration_id = ('registration_id');
1212

1313
$client = new JPush($app_key, $master_secret);
1414

1515
// 简单推送示例
1616
// 这只是使用样例,不应该直接用于实际生产环境中 !!
1717

18-
$push_payload = $client->push()
19-
->setPlatform('all')
20-
->addAllAudience()
21-
->setNotificationAlert('Hi, JPush');
22-
try {
23-
$response = $push_payload->send();
24-
print_r($response);
25-
} catch (\JPush\Exceptions\APIConnectionException $e) {
26-
// try something here
27-
print $e;
28-
} catch (\JPush\Exceptions\APIRequestException $e) {
29-
// try something here
30-
print $e;
31-
}
18+
// $push_payload = $client->push()
19+
// ->setPlatform('all')
20+
// ->addAllAudience()
21+
// ->setNotificationAlert('Hi, JPush');
22+
// try {
23+
// $response = $push_payload->send();
24+
// print_r($response);
25+
// } catch (\JPush\Exceptions\APIConnectionException $e) {
26+
// // try something here
27+
// print $e;
28+
// } catch (\JPush\Exceptions\APIRequestException $e) {
29+
// // try something here
30+
// print $e;
31+
// }
3232

3333
// 完整的推送示例
3434
// 这只是使用样例,不应该直接用于实际生产环境中 !!
@@ -44,7 +44,7 @@
4444
// ->addRegistrationId($registration_id)
4545
->addAllAudience()
4646

47-
->setNotificationAlert('Hi, JPush')
47+
->setNotificationAlert('Test custom')
4848
->iosNotification('Hello IOS', array(
4949
'sound' => 'sound.caf',
5050
// 'badge' => '+1',
@@ -90,12 +90,12 @@
9090
// 默认 86400 (1 天),最长 10 天。设置为 0 表示不保留离线消息,只有推送当前在线的用户可以收到
9191
// 这里设置为 1 仅作为示例
9292

93-
// 'time_to_live' => 1,
93+
'time_to_live' => 1,
9494

9595
// apns_production: 表示APNs是否生产环境,
9696
// True 表示推送生产环境,False 表示要推送开发环境;如果不指定则默认为推送开发环境
9797

98-
'apns_production' => false,
98+
// 'apns_production' => false,
9999

100100
// big_push_duration: 表示定速推送时长(分钟),又名缓慢推送,把原本尽可能快的推送速度,降低下来,
101101
// 给定的 n 分钟内,均匀地向这次推送的目标用户推送。最大值为1400.未设置则不是定速推送
@@ -112,6 +112,22 @@
112112
),
113113
'active_filter' => false
114114
))
115+
// custom可自定义最外层参数,如skd未支持部分文档功能,用户可自行写入
116+
// 这里仅作为例子展示
117+
// ->custom(array(
118+
// 'sms_message' => array(
119+
// 'active_filter' => false,
120+
// 'delay_time' => 60,
121+
// 'signid' => 154,
122+
// 'temp_id' => 1,
123+
// 'temp_para' => array(
124+
// 'code' => 357
125+
// )),
126+
// 'options' => array(
127+
// 'apns_production' => false,
128+
// 'time_to_live' => 62000,
129+
// )
130+
// ))
115131
->send();
116132
print_r($response);
117133

src/JPush/PushPayload.php

+18-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class PushPayload {
2929
private $smsMessage;
3030
private $message;
3131
private $options;
32+
private $custom;
3233

3334
/**
3435
* PushPayload constructor.
@@ -311,6 +312,12 @@ public function build() {
311312

312313
$payload['options'] = $this->options;
313314

315+
if (!is_null($this->custom)) {
316+
foreach($this->custom as $key=>$val) {
317+
$payload[$key] = $val;
318+
}
319+
}
320+
314321
return $payload;
315322
}
316323

@@ -446,14 +453,14 @@ public function androidNotification($alert = '', array $notification = array())
446453
* could add any custom key/value into it
447454
*/
448455
public function voip (array $extras = array()) {
449-
$voipBuilder = array();
456+
$voip = array();
450457
if(!empty($extras)) {
451458
foreach($extras as $key=>$val) {
452-
$voipBuilder[$key] = $val;
459+
$voip[$key] = $val;
453460
}
454461
}
455-
$voipBuilder = array_merge($extras, $voipBuilder);
456-
$this->voip=$voipBuilder;
462+
$voip = array_merge($extras, $voip);
463+
$this->voip=$voip;
457464
return $this;
458465
}
459466

@@ -509,6 +516,13 @@ public function options(array $opts = array()) {
509516
return $this;
510517
}
511518

519+
public function custom (array $extras = array()) {
520+
if(!empty($extras)) {
521+
$this->custom=$extras;
522+
}
523+
return $this;
524+
}
525+
512526
###############################################################################
513527
############# 以下函数已过期,不推荐使用,仅作为兼容接口存在 #########################
514528
###############################################################################

0 commit comments

Comments
 (0)