erickskrauch / fcm
PHP应用服务器,用于Google Firebase云消息(FCM)
0.3.0
2024-07-29 18:51 UTC
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- php-http/discovery: ^1.4
- psr/http-client: ^1.0
- psr/http-client-implementation: ^1.0
- psr/http-factory: ^1.0
- psr/http-factory-implementation: ^1.0
Requires (Dev)
- ely/php-code-style: ^0.4.0
- ergebnis/composer-normalize: ^2.28
- infection/infection: ^0.26.6
- nyholm/psr7: ^1.3
- php-http/mock-client: ^1.5
- phpstan/extension-installer: ^1
- phpstan/phpstan: ^1
- phpstan/phpstan-phpunit: ^1
- phpstan/phpstan-strict-rules: ^1
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2024-08-29 19:00:37 UTC
README
这只是通过Firebase云消息(FCM)发送推送通知的另一个客户端。实现灵感来源于Paragraph1/php-fcm及其分支guigpm/php-fcm,但经过大量重构,以实现更简洁的代码和更好的实现。
安装
此库依赖于PSR-18,它定义了如何发送和接收HTTP消息。您可以使用任何实现了psr/http-client-implementation的库来发送HTTP消息。有关PSR-18的更多信息,请参阅此博客。
要使用Guzzle安装此库,您可能需要运行以下命令
composer require erickskrauch/fcm guzzlehttp/guzzle
或者使用curl客户端(如果您不使用Guzzle,则需要提供例如nyholm/psr7的PSR7实现)
composer require erickskrauch/fcm php-http/curl-client nyholm/psr7
用法
组件的构造函数允许您明确传递所有依赖项。但您也可以仅传递必填的API令牌,所有其他依赖项将自动查找。下面的示例依赖于自动发现。
use ErickSkrauch\Fcm\Client; use ErickSkrauch\Fcm\Message\Message; use ErickSkrauch\Fcm\Message\Notification; use ErickSkrauch\Fcm\Recipient\Device; $client = new Client('SERVICE ACCOUNT OAUTH TOKEN', 'project-x146w'); $notification = new Notification(, 'testing body'); $notification->setTitle('Wow, something happened...'); $notification->setBody('It just works!'); $message = new Message(); $message->setNotification($notification); $message->setCollapseKey('collapse.key'); $recipient = new Device('your-device-token'); // or new ErickSkrauch\Fcm\Recipient\Topic('topic'); $result = $client->send($message, $recipient);
贡献
此库是开源的,遵循MIT许可证。因此,它由协作者和贡献者维护。
请随意以任何方式贡献。例如,您可以
- 尝试使用
master
代码。 - 如果您发现问题,请创建问题。
- 回复其他人的问题。
- 审查PR。
确保代码质量
该项目有多个质量控制工具。所有检查都在CI中执行,但如果您想要在本地执行检查,以下是一些必要的命令
vendor/bin/php-cs-fixer fix -v
vendor/bin/phpstan analyse
vendor/bin/phpunit
vendor/bin/infection # Try "env XDEBUG_MODE=coverage vendor/bin/infection" in case of errors