guanguans/yii-jpush
Composer 安装命令:
composer require guanguans/yii-jpush
包简介
适配于 Yii 的极光扩展包
README 文档
README
适配于 Yii 的极光推送扩展包
环境要求
- yii >= 2
安装
$ composer require guanguans/yii-jpush --prefer-dist -v
配置
Yii2 配置文件 config/main.php 的 components 中添加:
'components' => [ // ... 'jpush' => [ 'class' => 'Guanguans\YiiJpush\Jpush', 'appKey' => 'xxxxxxxxxxx', 'masterSecret' => 'xxxxxxxxxxx', 'logFile' => './jpush.log', // 可选 'retryTimes' => 3, // 可选 'zone' => 'default', // 可选 [default, bj] ], // ... ]
使用,更多详细文档请参考 jpush/jpush-api-php-client
获取 JPush\Client 实例
<php Yii::$app->jpush->client
简单使用
<?php Yii::$app->jpush->client->push() ->setPlatform('all') ->addAllAudience() ->setNotificationAlert('Hello, JPush') ->send();
/** * @param string $content 推送内容 * @param array $ids 推送的id * @param string $info 业务内容 * @param string $title 推送标题 定向的简单推送 不填 */ Yii::$app->jpush->client->push() ->setPlatform(['ios', 'android']) ->addRegistrationId($ids) ->iosNotification([ "title" => $title, "body" => $content ], [ 'sound' => 'sound.caf', 'badge' => '+1', 'content-available' => true, 'mutable-content' => true, 'category' => 'jiguang', 'extras' => [ 'info' => $info, ], ]) ->androidNotification($content, [ 'title' => $title, 'extras' => [ 'info' => $info, ], ]) ->options([ // true 表示推送生产环境,false 表示要推送开发环境;如果不指定则默认为推送开发环境 'apns_production' => false, ]) ->send();
异常处理
<?php $pusher = Yii::$app->jpush->client->push(); $pusher->setPlatform('all'); $pusher->addAllAudience(); $pusher->setNotificationAlert('Hello, JPush'); try { $pusher->send(); } catch (\Exception $e) { // try something else here echo $e; }
测试
$ composer test
License
统计信息
- 总下载量: 106
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-27
