此包已被弃用,不再维护。未建议替代包。

Android GCM 推送通知通道

v0.4.0 2019-03-02 14:10 UTC

This package is auto-updated.

Last update: 2020-09-26 15:47:19 UTC


README

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

此包使得使用 Google Cloud Messaging (GCM) 通过 Laravel 5.8 发送通知变得简单。

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

谷歌已于 2019 年 4 月 11 日弃用/停止使用 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()
            ->title('Account approved')
            ->message("Your {$notifiable->service} account was approved!");
    }
}

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

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

可用的方法

  • title($str)
  • message($str)
  • priority(GcmMessage::PRIORITY_NORMALGcmMessage::PRIORITY_HIGH)
  • data($key, $mixed)
  • notification($key, $mixed)
  • action($action, $params) (将设置 action 数据键)

更新日志

请参阅 CHANGELOG 以获取更多信息。

测试

$ composer test

安全

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

贡献

请参阅 CONTRIBUTING 以获取详细信息。

鸣谢

许可

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