djiele/simple-fire-cloud-messaging

发送webpush通知,管理对主题和组的订阅

dev-master 2019-12-08 11:15 UTC

This package is auto-updated.

Last update: 2024-09-05 18:07:53 UTC


README

另一个轻量级且易于使用的FCM (Firebase Cloud Messaging) 库。

注意:此库封装了旧的Firebase HTTP API,我不知道它何时会过时。

安装

您可以通过composer安装此包

composer require djiele/simple-fire-cloud-messaging "dev-master"
简单用法
require_once __DIR__'./vendor/autoload.php';
use Djiele\Fcm\WebPushNotifications;
$notifier = new WebPushNotifications('<YOUR_SERVER_KEY>', '<YOUR_SENDER_ID>');
$notifier->batchSubscribeTopic('<YOUR_TOPIC>', ['<DEVICE_TOKEN1>', '<DEVICE_TOKEN2>']);
$response = $notifier->sendToTopic('<YOUR_TOPIC>', 'What time is it?', 'The time is ' . date('H:i:s'), ['lottery' => (0 == rand(0, 100)%2)]);
print_r($response);
功能

将一个或多个设备订阅到指定的主题

$response = $notifier->batchSubscribeTopic('<YOUR_TOPIC>', ['<DEVICE_TOKEN1>', '<DEVICE_TOKEN2>']);
print_r($response);```

将一个或多个设备从指定的主题取消订阅

$response = $notifier->batchUnsubscribeTopic('<YOUR_TOPIC>', ['<DEVICE_TOKEN1>', '<DEVICE_TOKEN2>']);
print_r($response);

将单个设备订阅到主题

$response = $notifier->subscribeTopic('<YOUR_TOPIC>', '<DEVICE_TOKEN>');
print_r($response);

向主题发送通知

$response = $notifier->sendToTopic('<YOUR_TOPIC>', 'What time is it?', 'The time is ' . date('H:i:s'), ['lottery' => (0 == rand(0, 100)%2)]);
print_r($response);