daldan26/fcmv1

FCM HTTP V1 包

v1.0.4 2024-08-28 14:56 UTC

This package is not auto-updated.

Last update: 2024-09-25 15:24:52 UTC


README

这是一个 Laravel 扩展包,允许您轻松使用新的 FCM Http V1 API 发送推送通知。

Firebase

  1. 前往 Firebase 控制台

Laravel

FCM_API_KEY="<firebase apiKey>"
FCM_AUTH_DOMAIN="<firebase authDomain>"
FCM_PROJECT_ID="<firebase projectId>"
FCM_STORAGE_BUCKET="<firebase storageBucket>"
FCM_MESSAGIN_SENDER_ID="<firebase messagingSenderId>"
FCM_APP_ID="<firebase appId>"
FCM_JSON="<name of the json file downloaded at firebase step 7 install>"
FCM_API_SERVER_KEY=<api server key step 8-9 of firebase install>
  1. 包安装
composer require daldan26/fcmv1
  1. 在 config/app.php 中注册提供者
Daldan26\Fcmv1\FcmProvider::class,
  1. 发布配置文件
php artisan vendor:publish --tag=fcmv1 --ansi --force

用法

主题

主题用于创建设备令牌组。它们将允许您直接向用户已注册的主题发送通知。

订阅

要将令牌订阅到主题

use Daldan26\Fcmv1\FcmTopicHelper;

$tokens = ["first token", ... , "last token"];
FcmTopicHelper::subscribeToTopic($tokens, "myTopic");

取消订阅

use Daldan26\Fcmv1\FcmTopicHelper;

$tokens = ["first token", ... , "last token"];
FcmTopicHelper::unsubscribeToTopic($tokens, "myTopic");

列出订阅

use Daldan26\Fcmv1\FcmTopicHelper;

$token = "your awesome device token";
FcmTopicHelper::getTopicsByToken($token);

通知

您可以向特定用户或主题发送通知。

向令牌发送

use Daldan26\Fcmv1\FcmNotification;

$notify = new FcmNotification();
$notify->setTitle("Title")->setBody("Message here")->setToken(["token_here"])->setClickAction("NEWS")->send();

向主题发送

use Daldan26\Fcmv1\FcmNotification;

$notify = new FcmNotification();
$notify->setTitle("Title")->setBody("Message here")->setTopic("general_topic")->setClickAction("NEWS")->send();