idstack/laravel-fcm

用于跨 Laravel 应用发送 Firebase 通知的包

1.0.0 2017-11-18 15:07 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:01:35 UTC


README

一个简单的包,用于使用 FCM 作为推送通知。支持多个 token 或设备 ID,并可以按主题发送。

安装

您可以通过 composer 拉取此包

$ composer require idstack/laravel-fcm

注册服务提供者

'Providers' => [
   ...
   Idstack\Fcm\FcmServiceProvider::class,
]

可选:使用外观

'aliases' => [
    ...
    'Fcm' => Idstack\Fcm\Facades\Fcm::class,
];

发布配置文件以定义您的服务器密钥

php artisan vendor:publish --provider="Idstack\Fcm\FcmServiceProvider"

这是发布文件的包含内容

return [
    /**
     * Insert your FCM Server Key Here
     * Or you can add in env file with FCM_SERVER_KEY variable
     */
    'fcm_server_key' => env('FCM_SERVER_KEY','')
];

使用方法

此示例用于向具有标题和正文等信息的任何设备发送通知

fcm()
    ->data([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->to($recipients); // $recipients must an array

此示例用于使用主题发送通知,具有标题和正文等信息的示例

fcm()
    ->data([
        'title' => 'Test FCM',
        'body' => 'This is a test of FCM',
    ])
    ->toTopics($recipients); // $recipients must an array