Skip to content

Commit 8f2b78c

Browse files
committed
Update Voip
1 parent 8817ba8 commit 8f2b78c

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

README.md

+2-14
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414

1515
#### 使用 Composer 安装
1616

17-
- 在项目中的 `composer.json` 文件中添加 jpush 依赖:
18-
19-
```json
20-
"require": {
21-
"jpush/jpush": "*"
22-
}
23-
```
24-
2517
- 执行 `$ php composer.phar install``$ composer install` 进行安装。
2618

2719
#### 直接下载源码安装
@@ -95,14 +87,10 @@ try {
9587

9688
在下载的中的 [examples](https://github.com/jpush/jpush-api-php-client/tree/master/examples) 文件夹有简单示例代码, 开发者可以参考其中的样例快速了解该库的使用方法。
9789

98-
> **注:所下载的样例代码不可马上使用,需要在 `examples/config.php` 文件中填入相关的必要参数,或者设置相关环境变量,不进行这个操作则示例运行会失败。**另外为保护开发者隐私 examples/config.php 文件不在版本控制中,需要使用如下命令手动复制:
99-
100-
```bash
101-
$ cp examples/config.php.example examples/config.php
102-
```
103-
10490
**简单使用方法**
10591

92+
先填写对应的appKey和masterSecret,可以额外设定Registration_id。
93+
10694
若要运行 push_example.php 中的示例代码:
10795

10896
``` bash

examples/push_example.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
<?php
22
// 这只是使用样例,不应该直接用于实际生产环境中 !!
33

4-
require 'config.php';
4+
require __DIR__ . '/../autoload.php';
5+
6+
use JPush\Client as JPush;
7+
8+
// 这里填写appKey,masterSecret以及registration_id
9+
$app_key = 'your AppKey';
10+
$master_secret = 'your MasterSecret';
11+
$registration_id = ('registration_id');
12+
13+
$client = new JPush($app_key, $master_secret);
514

615
// 简单推送示例
716
// 这只是使用样例,不应该直接用于实际生产环境中 !!
@@ -55,6 +64,12 @@
5564
'jiguang'
5665
),
5766
))
67+
// voip可以传输任意键值对,可用作自定义
68+
->voip(array(
69+
'test123' => 'val1',
70+
'jsontest' => 2,
71+
'booleantest' => true
72+
))
5873
->message('message content', array(
5974
'title' => 'hello jpush',
6075
// 'content_type' => 'text',

src/JPush/PushPayload.php

+21
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class PushPayload {
2525
private $iosNotification;
2626
private $androidNotification;
2727
private $winPhoneNotification;
28+
private $voip;
2829
private $smsMessage;
2930
private $message;
3031
private $options;
@@ -285,6 +286,10 @@ public function build() {
285286
}
286287
}
287288

289+
if (!is_null($this->voip)) {
290+
$notification['voip'] = $this->voip;
291+
}
292+
288293
if (count($notification) > 0) {
289294
$payload['notification'] = $notification;
290295
}
@@ -436,6 +441,22 @@ public function androidNotification($alert = '', array $notification = array())
436441
return $this;
437442
}
438443

444+
/**
445+
* Voip in notification
446+
* could add any custom key/value into it
447+
*/
448+
public function voip (array $extras = array()) {
449+
$voipBuilder = array();
450+
if(!empty($extras)) {
451+
foreach($extras as $key=>$val) {
452+
$voipBuilder[$key] = $val;
453+
}
454+
}
455+
$voipBuilder = array_merge($extras, $voipBuilder);
456+
$this->voip=$voipBuilder;
457+
return $this;
458+
}
459+
439460
public function message($msg_content, array $msg = array()) {
440461
# $required_keys = array('title', 'content_type', 'extras');
441462
if (is_string($msg_content)) {

0 commit comments

Comments
 (0)