witty / laravel-push-notification
Laravel 5 包,用于向 Android 和 iOS 设备发送推送通知
1.0.0
2015-11-11 07:20 UTC
Requires
- php: >=5.4.0
- illuminate/support: 5.0.* | 5.1.*
- sly/notification-pusher: 2.x
This package is auto-updated.
Last update: 2024-09-20 15:45:48 UTC
README
基于 https://github.com/davibennun/laravel-push-notification 开发,支持 Laravel 5 和 5.1。
安装
更新你的 composer.json
文件,将其作为依赖项包含
"witty/laravel-push-notification": "dev-master"
通过将 PushNotification 服务提供者添加到 config/app.php
文件中的 providers 数组来注册 PushNotification 服务提供者。
'providers' => array( 'Witty\LaravelPushNotification\PushNotificationServiceProvider' )
通过在 config/app.php
文件中的 aliases 数组中添加 PushNotification 门面来别名 PushNotification。
'aliases' => array( 'PushNotification' => 'Witty\LaravelPushNotification\PushNotification', )
配置
通过运行以下命令将配置文件复制到你的项目中
php artisan vendor:publish
这将生成一个如下的配置文件
array( 'iOS' => [ 'environment' => env('IOS_PUSH_ENV', 'development'), 'certificate' => env('IOS_PUSH_CERT', __DIR__ . '/ios-push-notification-certificates/development/certificate.pem'), 'passPhrase' => env('IOS_PUSH_PASSWORD', '291923Job'), 'service' => 'apns' ], 'android' => [ 'environment' => env('ANDROID_PUSH_ENV', 'development'), 'apiKey' => env('ANDROID_PUSH_API_KEY', 'yourAPIKey'), 'service' => 'gcm' ] );
其中所有第一级键对应于服务配置,每个服务都有自己的属性,例如,Android 有 apiKey
,而 iOS 使用 certificate
和 passPhrase
。你可以设置任意多的服务配置,每个应用一个。将在配置文件夹中添加一个名为 'ios-push-notification-certificates' 的目录,以便你存储开发和生产证书。
不要忘记将 service
键设置为标识 iOS 'service'=>'apns'
和 Android 'service'=>'gcm'
用法
PushNotification::app('iOS') ->to($deviceToken) ->send('Hello World, i`m a push message');