iansltx / gcm-client
Android 消息 API 的 Firebase Cloud Messaging 客户端(通过旧端点)
Requires
- php: ^7.2
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^8.1
- scrutinizer/ocular: ^1.5.2
README
gcm-client 是一个用于与 Android 的 Google Cloud Messaging HTTP API 交互的 PHP 库。它可以用来向 Android 注册 ID 和通知密钥(用于基于用户的多设备消息)发送消息。它还可以创建和操作通知密钥。
此库应遵循 PSRs 1、2 和 4,并需要 PHP 7.2 或更高版本。
安装
通过 Composer
$ composer require iansltx/gcm-client
如果您不想使用 Composer,可以直接从 GitHub 下载源代码压缩包,并使用符合 PSR-4 的自动加载器加载它。如果您没有这样的自动加载器,请引入 autoload.php
以获取适用于此库的自动加载器。
使用
<?php require "vendor/autoload.php"; $client = new iansltx\GCMClient\Client(YOUR_GCM_API_KEY); $message = new iansltx\GCMClient\Message(['title' => 'Notification', 'message' => 'Hello World!']); // send directly to one or more Registration IDs $regIdResult = $client->sendToRegIds($message, ['regId1', 'regId2']); $singleRegIdResult = $client->sendToRegIds($message, 'regId3'); // create a Notification Key for user-based messaging and send to that $nkClient = $client->withProjectId('myProjectId'); // a project ID is required for notification key manipulation $key = $nkClient->createNotificationKey('myUniqueKeyName', ['regId1', 'regId2']); $nkClient->addToNotificationKey($key, ['regId3'], 'myUniqueKeyName'); // returns the notification key $nkClient->removeFromNotificationKey($key, ['regId1'], 'myUniqueKeyName'); // returns the notification key $nKeyResult = $client->sendToNotificationKey($key, $message); // could use $nkClient to send as well
请参阅 Client 和 Message 的 docblocks 以获取更多信息。
Google 之前已经更改了消息发送端点中通知密钥字段的推荐位置。此库已更新到新的非弃用位置。此外,现在看起来他们在更新通知密钥时要求使用名称;以前这是可选的,因此它被放置在上面的调用中的最后一个参数。
从 v1.0 版本开始,此库使用 Google 的非弃用 FCM 旧端点(他们的说法,而不是我的想法),而不是将在 2019 年 5 月 29 日或之后下线的旧 GCM 端点。因此,尽管名称如此,此库可以在 2019 年 5 月之后与 Firebase Cloud Messaging 一起使用。
测试
$ composer test
目前使用 PHPUnit 进行测试。
贡献
有关详细信息,请参阅 CONTRIBUTING。
安全
如果您发现任何安全相关的问题,请通过电子邮件 iansltx@gmail.com 反馈,而不是使用问题跟踪器。
鸣谢
许可证
此库采用 BSD 2-clause 许可证。有关更多信息,请参阅 许可证文件。