guanguans 2020-09-30 14:16:38 1142次浏览 0条评论 0 0 0

yii-jpush

usage.png

适配于 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

    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册