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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章