Skip to content

Commit

Permalink
Update Voip
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiboZhang1 committed Aug 12, 2021
1 parent 8817ba8 commit 8f2b78c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
16 changes: 2 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@

#### 使用 Composer 安装

- 在项目中的 `composer.json` 文件中添加 jpush 依赖:

```json
"require": {
"jpush/jpush": "*"
}
```

- 执行 `$ php composer.phar install``$ composer install` 进行安装。

#### 直接下载源码安装
Expand Down Expand Up @@ -95,14 +87,10 @@ try {

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

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

**简单使用方法**

先填写对应的appKey和masterSecret,可以额外设定Registration_id。

若要运行 push_example.php 中的示例代码:

``` bash
Expand Down
17 changes: 16 additions & 1 deletion examples/push_example.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
<?php
// 这只是使用样例,不应该直接用于实际生产环境中 !!

require 'config.php';
require __DIR__ . '/../autoload.php';

use JPush\Client as JPush;

// 这里填写appKey,masterSecret以及registration_id
$app_key = 'your AppKey';
$master_secret = 'your MasterSecret';
$registration_id = ('registration_id');

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

// 简单推送示例
// 这只是使用样例,不应该直接用于实际生产环境中 !!
Expand Down Expand Up @@ -55,6 +64,12 @@
'jiguang'
),
))
// voip可以传输任意键值对,可用作自定义
->voip(array(
'test123' => 'val1',
'jsontest' => 2,
'booleantest' => true
))
->message('message content', array(
'title' => 'hello jpush',
// 'content_type' => 'text',
Expand Down
21 changes: 21 additions & 0 deletions src/JPush/PushPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PushPayload {
private $iosNotification;
private $androidNotification;
private $winPhoneNotification;
private $voip;
private $smsMessage;
private $message;
private $options;
Expand Down Expand Up @@ -285,6 +286,10 @@ public function build() {
}
}

if (!is_null($this->voip)) {
$notification['voip'] = $this->voip;
}

if (count($notification) > 0) {
$payload['notification'] = $notification;
}
Expand Down Expand Up @@ -436,6 +441,22 @@ public function androidNotification($alert = '', array $notification = array())
return $this;
}

/**
* Voip in notification
* could add any custom key/value into it
*/
public function voip (array $extras = array()) {
$voipBuilder = array();
if(!empty($extras)) {
foreach($extras as $key=>$val) {
$voipBuilder[$key] = $val;
}
}
$voipBuilder = array_merge($extras, $voipBuilder);
$this->voip=$voipBuilder;
return $this;
}

public function message($msg_content, array $msg = array()) {
# $required_keys = array('title', 'content_type', 'extras');
if (is_string($msg_content)) {
Expand Down

0 comments on commit 8f2b78c

Please sign in to comment.