yii-jpush - 适配于 Yii 的极光推送扩展包

yii-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

本作品采用《CC 协议》,转载必须注明作者和本文链接
No practice, no gain in one's wit. 我的 Gitub
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
55
粉丝
126
喜欢
971
收藏
1332
排名:46
访问:15.2 万
私信
所有博文
社区赞助商