dsnoeck / laravel-push-notification
Laravel 包,用于向移动设备发送推送通知(apns, gcm)
Requires
- php: >=5.3.0
- illuminate/support: ~4.2
- sly/notification-pusher: 2.*
This package is not auto-updated.
Last update: 2024-09-24 07:22:10 UTC
README
使设备能够发送推送通知的包
安装
更新你的 composer.json
文件,将此包作为依赖项包含。使用 "dev-master" 获取最新版本,使用 "4.0" 以兼容 Laravel 4.0,使用 "4.2" 以兼容 Laravel 4.2
"dsnoeck/laravel-push-notification": "dev-master"
通过将 PushNotification 服务提供者添加到 app/config/app.php
文件中的 providers 数组来注册 PushNotification 服务提供者。
'providers' => array(
Davibennun\LaravelPushNotification\LaravelPushNotificationServiceProvider
)
通过将 PushNotification 门面添加到 app/config/app.php
文件中的 aliases 数组来别名 PushNotification 门面。
'aliases' => array( 'PushNotification' => 'Davibennun\LaravelPushNotification\Facades\PushNotification' )
配置
通过运行以下命令将配置文件复制到你的项目中:
php artisan config:publish davibennun/laravel-push-notification
这将生成一个如下的配置文件
array(
'appNameIOS'=>array(
'environment'=>'development',
'certificate'=>'/path/to/certificate.pem',
'passPhrase'=>'password',
'service'=>'apns'
),
'appNameAndroid'=>array(
'environment'=>'production',
'apiKey'=>'yourAPIKey',
'service'=>'gcm'
)
);
其中所有第一级键对应于一个服务配置,每个服务都有其自己的属性,例如,Android 有 apiKey
,而 iOS 使用 certificate
和 passPhrase
。你可以设置尽可能多的服务配置,每个应用一个。
#####不要忘记将 service
键设置为识别 iOS 'service'=>'apns'
和 Android 'service'=>'gcm'
#####证书路径必须是绝对路径,因此在配置文件中你可以使用以下方式
//Path to the 'app' folder
'certificate'=>app_path().'/myCert.pem'
Laravel 函数也适用,例如 public_path()
storage_path()
base_path()
使用方法
PushNotification::app('appNameIOS') ->to($deviceToken) ->send('Hello World, i`m a push message');
其中 app 参数 appNameIOS
指的是配置文件中定义的服务。向多个设备和可选消息发送
$devices = PushNotification::DeviceCollection(array( PushNotification::Device('token', array('badge' => 5)), PushNotification::Device('token1', array('badge' => 1)), PushNotification::Device('token2') )); $message = PushNotification::Message('Message Text',array( 'badge' => 1, 'sound' => 'example.aiff', 'actionLocKey' => 'Action button title!', 'locKey' => 'localized key', 'locArgs' => array( 'localized args', 'localized args', 'localized args' ), 'launchImage' => 'image.jpg', 'custom' => array('custom data' => array( 'we' => 'want', 'send to app' )) )); PushNotification::app('appNameIOS') ->to($devices) ->send($message);
此包封装了 Notification Package 并为其添加了一些功能。
####使用建议 此包应与 Laravel Queues 一起使用,这样推送就不会阻塞用户,并且在后台处理,这意味着更好的流程。
##许可证
The Laravel 框架是开源软件,根据 [MIT 许可证] 许可。