guanguans/yii-jpush 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

guanguans/yii-jpush

Composer 安装命令:

composer require guanguans/yii-jpush

包简介

适配于 Yii 的极光扩展包

README 文档

README

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

Scrutinizer Code Quality codecov StyleCI Latest Stable Version Total Downloads License

环境要求

  • 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

MIT

统计信息

  • 总下载量: 106
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固