baudev/fcm-xmpp
Composer 安装命令:
composer require baudev/fcm-xmpp
包简介
Allows XMPP connection with Firebase Cloud Messaging. It can listen upstream messages and send downstream ones.
README 文档
README
| Service | Master | Develop |
|---|---|---|
| CI Status | ||
| Version | ||
| PHP version |
This PHP program, based on the unmaintained sourc7/FCMStream repository, allows receiving and sending messages with the XMPP Protocol using Firebase Cloud Messaging.
INSTALLATION
composer require baudev/fcm-xmpp
EXAMPLES
- Create an
index.phpfile and write into it one of the two following script (method1 or method2). Don't forget replacing :SENDER_ID,SERVER KEY. - Run the script:
php index.php
Note: examples are provided in the directory examples. More explanations can be found into the wiki page.
1. Using a class (best solution):
class YOURCLASSNAME extends \FCMStream\Core { public function onSend(string $from, string $messageId, Actions $actions) { // TODO: Implement onSend() method. } public function onReceipt(string $from, string $messageId, string $status, int $timestamp, Actions $actions) { // TODO: Implement onReceipt() method. } public function onReceiveMessage($data, int $timeToLive, string $from, string $messageId, string $packageName, Actions $actions) { // we answer to the message received $message = new \FCMStream\Message(); $message->setTo($from); $message->setMessageId("message_id_test"); $message->setPriority(\FCMStream\Message::PRIORITY_HIGH); $message->setData(array("test" => "Hello World!")); $actions->sendMessage($message); } /** * The method is executed each X microseconds. * To enable this method, you must execute enableOnLoopMethod() * !! Warning !! Enabling this method can increase a lot the usage of your CPU! * @param Actions $actions */ public function onLoop(Actions $actions) { // TODO: Implement onLoop() method. } public function onFail(?string $error, ?string $errorDescription, ?string $from, ?string $messageId, Actions $actions) { // TODO: Implement onFail() method. } public function onExpire(string $from, string $newFCMId, Actions $actions) { // TODO: Implement onExpire() method. } } $test = new YOURCLASSNAME('SENDER_ID', 'SERVER KEY', 'debugfile.txt', \FCMStream\helpers\Logs::DEBUG); // $test->enableOnLoopMethod(5 * 1000 * 1000); // enables the onLoop method. She will be called each 5 seconds. // Before uncommenting the previous line, see https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/wiki/References#enableonloopmethodmicroseconds $test->stream();
2. Using function callback parameters:
$test = new FCMStream\Callbacks('SENDER_ID', 'SERVER KEY', 'debugfile.txt', \FCMStream\helpers\Logs::ANY); // onSend callback $test->setOnSend(function (string $from, string $messageId, Actions $actions){ // TODO: Implement onSend() method. }); // onReceipt callback $test->setOnReceipt(function (string $from, string $messageId, string $status, int $timestamp, Actions $actions) { // TODO: Implement onReceipt() method. }); // onReceiveMessage callback $test->setOnReceiveMessage(function ($data, int $timeToLive, string $from, string $messageId, string $packageName, Actions $actions){ // we answer to the message received $message = new \FCMStream\Message(); $message->setTo($from); $message->setMessageId("message_id_test"); $message->setPriority(\FCMStream\Message::PRIORITY_NORMAL); $message->setData(array("test" => "Hello World!")); $actions->sendMessage($message); }); // onLoop callback // To enable this method, you must execute enableOnLoopMethod() // !! Warning !! Enabling this method can increase a lot the usage of your CPU! $test->setOnLoop(function (Actions $actions) { // TODO: Implement onLoop() method. }); // onFail callback $test->setOnFail(function (?string $error, ?string $errorDescription, ?string $from, ?string $messageId, Actions $actions) { // TODO: Implement onFail() method. }); // onExpire callback $test->setOnExpire(function (string $from, string $newFCMId, Actions $actions){ // TODO: Implement onExpire() method. }); // $test->enableOnLoopMethod(5 * 1000 * 1000); // enables the onLoop method. She will be called each 5 seconds. // Before uncommenting the previous line, see https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/wiki/References#enableonloopmethodmicroseconds $test->stream();
USAGE
- Downstream Messages: server-to-device through FCM
- Upstream Messages: device-to-server through FCM
DOCUMENTATION
See the wiki page to discover every possibilities provided by this framework.
TODO
- Add more comments
- Add methods for responding easily, to set message priority and so on. Notification property is not handled yet
- Improve README
- Add more tests
CREDITS
- Images in the USAGE part are coming from the XAMARIN documentation.
- Major part of the code is coming from the sourc7/FCMStream repository. As it is unmaintained, I allow myself to fork it and improve it.
LICENSE
MIT License
Copyright (c) 2016 Ante Radman (Radoid), Irvan Kurniawan (TechRapid), Baudev.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
baudev/fcm-xmpp 适用场景与选型建议
baudev/fcm-xmpp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 498 次下载、GitHub Stars 达 16, 最近一次更新时间为 2018 年 06 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「messaging」 「cloud」 「xmpp」 「firebase」 「FCM」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 baudev/fcm-xmpp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 baudev/fcm-xmpp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 baudev/fcm-xmpp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
UCloud Resource (Cloud) Storage SDK for PHP
The flysystem adapter for yandex disk rest api.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
非官方云小票机SDK,支持飞鹅云,芯烨云,易联云,快递100,映美云,中午云,佳博云,优声云,365智能云打印等
统计信息
- 总下载量: 498
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-21

