httd1/fcmclient
最新稳定版本:v1.0.0
Composer 安装命令:
composer require httd1/fcmclient
包简介
A simple FCM client for PHP
README 文档
README
A simple PHP client to send messages with Firebase Cloud Messaging (FCM) using the HTTP v1 API.
It does not rely on the official Google SDK, only guzzlehttp/guzzle and firebase/php-jwt.
📦 Installation
Install via Composer:
composer require httd1/fcmclient
⚙️ Setup
Download the private key JSON file in the Firebase Console.
Place this file in your project, ex. firebase-credentials.json.
🚀 Usage
Send to a single device
<?php require 'vendor/autoload.php'; use FcmClient\FcmClient; try { // initialize client with service account JSON $client = new FcmClient(__DIR__ . '/firebase-credentials.json'); // send notification $response = $client->send([ 'message' => [ 'token' => 'FCM_DEVICE_TOKEN_HERE', 'notification' => [ 'title' => 'Hello!', 'body' => 'Test notification 🚀' ] ] ]); print_r($response); } catch (\Throwable $e) { echo 'Error: ' . $e->getMessage(); }
Send to a topic
$response = $client->send([ 'message' => [ 'topic' => 'my_app_topic', 'notification' => [ 'title' => 'Update', 'body' => 'Message sent to all subscribers of the topic' ] ] ]); print_r($response);
Send with custom data payload
$response = $client->send([ 'message' => [ 'token' => 'FCM_DEVICE_TOKEN_HERE', 'data' => [ 'action' => 'open_chat', 'chat_id' => '12345' ] ] ]);
📚 References
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-28