icemix / laravel-fcm-notification-channel

Icemix Firebase云消息通知驱动

V1.2 2020-03-05 21:13 UTC

This package is auto-updated.

Last update: 2024-08-25 21:12:34 UTC


README

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

内容

安装

您可以通过composer安装此包

composer require icemix/laravel-fcm-notification-channel:1.0

在您的应用配置文件 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:向设备发送通知。
  • FCMMessageTopic:向主题发送通知。
  • FCMMessageGroup:向组发送通知。

为了让您的通知知道向谁发送消息,您必须将 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)。请参阅许可文件以获取更多信息。