asachanfbd/laravel-push-notification

Laravel 5 包,用于向 Android 和 iOS 设备发送推送通知。与 witty 的相同,增加了对 Laravel 5.2 的支持。

v1.0.1 2016-04-20 15:39 UTC

This package is not auto-updated.

Last update: 2024-09-26 01:33:18 UTC


README

基于 https://github.com/davibennun/laravel-push-notification 分支,由 https://github.com/larkinwhitaker/laravel-push-notification 分支 fork。

增加了对 Laravel 5.2.* 的支持。

安装

安装包

composer require asachanfbd/laravel-push-notification

通过在 config/app.php 文件中将 PushNotification 服务提供者添加到 providers 数组中来注册 PushNotification 服务提供者。

'providers' => array(
    'Asachanfbd\LaravelPushNotification\PushNotificationServiceProvider'
)

通过在 config/app.php 文件中将 PushNotification 门面添加到 aliases 数组中来别称 PushNotification 门面。

'aliases' => array(
	'PushNotification'      => 'Asachanfbd\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 使用 certificatepassPhrase。您可以设置尽可能多的服务配置,每个应用程序一个。将在配置文件夹中添加一个名为 'ios-push-notification-certificates' 的目录,以便存储开发和生产证书。

别忘了将 service 键设置为用于标识 iOS 'service'=>'apns' 和 Android 'service'=>'gcm'

使用

PushNotification::app('iOS')
                ->to($deviceToken)
                ->send('Hello World, i`m a push message');

使用建议

此包应与 Laravel Queues 一起使用,这样推送不会阻塞用户,并在后台处理,这意味着更好的流程。