bryglen/yii2-apns-gcm
Yii 2 使用 Apns 和 Gcm 结合
1.0.5
2017-04-25 12:05 UTC
Requires
- duccio/apns-php: 1.0.1
- php-gcm/php-gcm: ^1.1.1
This package is not auto-updated.
Last update: 2024-09-14 15:21:51 UTC
README
Yii 2 通过公共方法如 send()
和 sendMulti()
使用 Apns 和 Gcm
安装
安装此扩展的首选方式是通过 composer.
运行
php composer.phar require --prefer-dist bryglen/yii2-apns-gcm "1.0.5"
或者
"bryglen/yii2-apns-gcm": "1.0.5"
将其添加到你的 composer.json
文件的 require 部分。
在你的 main.php 文件中,配置看起来像这样
'components' => [ 'apns' => [ 'class' => 'bryglen\apnsgcm\Apns', 'environment' => \bryglen\apnsgcm\Apns::ENVIRONMENT_SANDBOX, 'pemFile' => dirname(__FILE__).'/apnssert/apns-dev.pem', // 'retryTimes' => 3, 'options' => [ 'sendRetryTimes' => 5 ] ], 'gcm' => [ 'class' => 'bryglen\apnsgcm\Gcm', 'apiKey' => 'your_api_key', ], // using both gcm and apns, make sure you have 'gcm' and 'apns' in your component 'apnsGcm' => [ 'class' => 'bryglen\apnsgcm\ApnsGcm', // custom name for the component, by default we will use 'gcm' and 'apns' //'gcm' => 'gcm', //'apns' => 'apns', ] ]
在线测试器
请访问在线测试器链接 http://apns-gcm.bryantan.info
用法
仅使用 APNS 的用法
/* @var $apnsGcm \bryglen\apnsgcm\Apns */ $apns = Yii::$app->apns; $apns->send($push_tokens, $message, [ 'customProperty_1' => 'Hello', 'customProperty_2' => 'World' ], [ 'sound' => 'default', 'badge' => 1 ] );
仅使用 GCM 的用法
/* @var $apnsGcm \bryglen\apnsgcm\Gcm */ $gcm = Yii::$app->gcm; $gcm->send($push_tokens, $message, [ 'customerProperty' => 1, ], [ 'timeToLive' => 3 ], );
同时使用 APNS 和 GCM 的用法
使用 Google Cloud Messaging 发送
/* @var $apnsGcm \bryglen\apnsgcm\ApnsGcm */ $apnsGcm = Yii::$app->apnsGcm; $apnsGcm->send(\bryglen\apnsgcm\ApnsGcm::TYPE_GCM, $push_tokens, $message, [ 'customerProperty' => 1 ], [ 'timeToLive' => 3 ], )
使用 Apple 推送通知服务发送
/* @var $apnsGcm \bryglen\apnsgcm\ApnsGcm */ $apnsGcm = Yii::$app->apnsGcm; $apnsGcm->send(\bryglen\apnsgcm\ApnsGcm::TYPE_APNS, $push_tokens, $message, [ 'customerProperty' => 1 ], [ 'sound' => 'default', 'badge' => 1 ], )