yaim/laravel-fcm-notification-channel

Firebase云消息通知驱动

0.2.1 2019-03-07 09:03 UTC

This package is auto-updated.

Last update: 2024-09-14 19:36:57 UTC


README

此包可以轻松使用Firebase云消息(FCM)在Laravel 5.3中发送通知。此包基于brozot/laravel-fcm,因此请阅读该文档以获取更多信息。

内容

安装

您可以通过composer安装此包

composer require enniel/laravel-fcm-notification-channel:1.*

直接在您的应用配置文件 config/app.php 中注册提供者

'providers' => [
    // ...

    NotificationChannels\FCM\ServiceProvider::class 
]

用法

现在您可以在通知内的 via() 方法中使用该频道

use NotificationChannels\FCM\FCMMessage;
use Illuminate\Notifications\Notification;

class ExampleNotification extends Notification
{
    public function via($notifiable)
    {
        return ['fcm'];
    }

    public function toFCM($notifiable)
    {
        return (new FCMMessage())
            ->notification([
                'title' => 'Notification title',
                'body' => 'Notification body',
            ]);
    }
}

可用的消息类型

  • FCMMessage:向设备(s)发送通知。
  • FCMMessageTopic:向主题(s)发送通知。
  • FCMMessageGroup:向组(s)发送通知。

为了使您的通知知道向谁发送消息,您必须在您的通知模型中添加 routeNotificationForFCM 方法。

可用的消息方法

  • data():通知数据。 array | LaravelFCM\Message\PayloadData | LaravelFCM\Message\PayloadDataBuilder
  • options():通知选项。 array | LaravelFCM\Message\Options | LaravelFCM\Message\OptionsBuilder
  • notification():通知内容。 array | LaravelFCM\Message\PayloadNotification | LaravelFCM\Message\PayloadNotificationBuilder

代理方法。有关这些方法的更多信息,请参阅brozot/laravel-fcm

  • setDryRun
  • setPriority
  • setTimeToLive
  • setCollapseKey
  • setDelayWhileIdle
  • setMutableContent
  • setContentAvailable
  • setRestrictedPackageName
  • isDryRun
  • getPriority
  • getTimeToLive
  • getCollapseKey
  • isDelayWhileIdle
  • isMutableContent
  • isContentAvailable
  • getRestrictedPackageName
  • setTag
  • setBody
  • setIcon
  • setTitle
  • setSound
  • setBadge
  • setColor
  • setChannelId
  • setClickAction
  • setBodyLocationKey
  • setBodyLocationArgs
  • setTitleLocationKey
  • setTitleLocationArgs
  • getTag
  • getBody
  • getIcon
  • getTitle
  • getSound
  • getBadge
  • getColor
  • getChannelId
  • getClickAction
  • getBodyLocationKey
  • getBodyLocationArgs
  • getTitleLocationKey
  • getTitleLocationArgs

测试

$ composer test

致谢

支持

遇到问题?打开一个问题!

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件