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
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

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