piyushpatil/androidpushnotification

Laravel 包,用于向安卓移动设备发送推送通知(gcm)

dev-master 2015-04-13 05:17 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:31:17 UTC


README

启用向安卓设备发送推送通知的包。

安装

更新 composer.json 文件,将其作为依赖项包含

"piyushpatil/androidpushnotification": "dev-master"

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

'providers' => [
     'Piyushpatil\Androidpushnotification\AndroidpushnotificationServiceProvider',
]

通过将外观添加到 config/app.php 文件中的 aliases 数组中来别名 PushNotification 外观。

'aliases' => [
    'PushNotification' => 'Piyushpatil\Androidpushnotification\Facades\PushNotification',
]

配置

通过运行以下命令将配置文件复制到您的项目中

 php artisan vendor:publish --provider="piyushpatil/androidpushnotification" --tag="config"

这将生成一个如下所示的配置文件

    return [
    'Android' => [
        'environment' => 'production',
        'apiKey' => 'yourAPIKey',
        'service' => 'gcm'
    ]
];

其中所有一级键都对应于一个服务配置,每个服务都有自己的属性,例如安卓有 apiKey。您可以设置任意数量的服务配置,每个应用一个。

别忘了将 service 键设置为识别安卓 'service'=>'gcm'

其中 app 参数 Android 指的是配置文件中定义的服务。用于多个设备和可选的消息

In Controller file write this line.

use PushNotification; 


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


$devices = PushNotification::DeviceCollection(array(
    PushNotification::Device('token', array('badge' => 5)),
    PushNotification::Device('token1', array('badge' => 1)),
    PushNotification::Device('token2')
));

collection = PushNotification::app('Android')
    ->to($devices)
    ->send($message);

// get response for each device push
foreach ($collection->pushManager as $push) {
    $response = $push->getAdapter()->getResponse();
}

[Notification Package]:https://github.com/Ph3nol/NotificationPusher
[Laravel Queues]:http://laravel.net.cn/docs/queues