imageyii-jpush - 适配于 Yii 的极光推送扩展包
环境要求
- yii >= 2
安装
$ composer require guanguans/yii-jpush -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();
异常处理
<?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
MIT
网友评论