coder966 / fcm-simple
PHP库,用于Firebase云消息推送(FCM)
v4.0.0
2019-05-21 04:33 UTC
Requires
- php: >=5.6.0
Requires (Dev)
- phpunit/phpunit: 5.6.*
README
一个PHP库,用于通过Firebase云消息推送(FCM)向注册的设备发送消息。
特性
- 轻量级 & 简单
- 无依赖
- 使用cURL实现
- 支持发送到主题和令牌
- 支持多种消息选项,如
CollapseKey
、Priority
、TimeToLive
等 - 提供您应更新/删除数据库中的令牌
用法
更多信息,请参阅Wiki
安装
您需要PHP >= 5.4
$ composer require coder966/fcm-simple
PHP服务器
require 'vendor/autoload.php'; use FCMSimple\Client; use FCMSimple\Message; // create the client $client = new Client("YOUR_SERVER_KEY"); // create the message $msg = new Message(); $msg->put("key1", "value1"); $msg->put("key2", "value2"); // send the message to a specific topic $client->sendToTopic($msg, "my_topic"); // or you can send to specific devices using their registration tokens // so first prepare your array of tokens, typically retrieve from DB $tokens = [ "token_1", "token_2", "token_3" ]; // and send $client->sendToTokens($msg, $tokens);
Android客户端
在扩展FirebaseMessagingService
的服务中,在onMessageReceived
方法中使用
Map<String, String> msg = remoteMessage.getData(); String value1 = msg.get("key1"); String value2 = msg.get("key2");
许可证
Copyright 2016 Khalid H. Alharisi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://apache.ac.cn/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.