demian/laravel-notifications-gcm

Android GCM 推送通知通道

0.0.3 2016-11-09 16:48 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:37:43 UTC


README

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

此包简化了使用 Google Cloud Messaging (GCM) 通过 Laravel 5.3 发送通知的过程。

此包基于 ZendService\Google\Gcm,因此请阅读该文档以获取更多信息。

内容

安装

使用 Composer 安装此包

composer require laravel-notification-channels/gcm

在您的 config/app.php 中注册 ServiceProvider

NotificationChannels\Gcm\GcmServiceProvider::class,

设置 GCM 服务

您需要在 Google API 控制台中为您的应用程序注册 Google Cloud Messaging 的服务器密钥: https://console.cloud.google.com/apis/

将 API 密钥添加到您的 config/broadcasting.php 配置中

'connections' => [
  ....
  'gcm' => [
      'key' => env('GCM_KEY'),
  ],
  ...
]

使用

现在,您可以通过创建一个 GcmMessage 来向 GCM 发送消息

use NotificationChannels\Gcm\GcmChannel;
use NotificationChannels\Gcm\GcmMessage;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [GcmChannel::class];
    }

    public function toGcm($notifiable)
    {
        return GcmMessage::create()
            ->badge(1)
            ->title('Account approved')
            ->message("Your {$notifiable->service} account was approved!");
    }
}

在您的 notifiable 模型中,确保包含一个 routeNotificationForGcm() 方法,该方法返回一个或多个令牌。

public function routeNotificationForGcm()
{
    return $this->gcm_token;
}

可用方法

  • title($str)
  • message($str)
  • badge($integer)
  • priorty(GcmMessage::PRIORITY_NORMALGcmMessage::PRIORITY_HIGH)
  • data($key, $mixed)
  • action($action, $params) (将设置一个 action 数据键)

变更日志

请参阅 CHANGELOG 了解最近更改的内容。

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过电子邮件 info@fruitcake.nl 反馈,而不是使用问题跟踪器。

贡献

有关详细信息,请参阅 CONTRIBUTING

鸣谢

许可

MIT 许可证 (MIT)。请参阅 许可文件 获取更多信息。