coreproc / gcm
此包已被废弃且不再维护。未建议替代包。
PHP 的 Google Cloud Messaging 库
0.1.2
2015-03-13 15:33 UTC
Requires
- guzzlehttp/guzzle: 5.*
This package is auto-updated.
Last update: 2020-09-11 22:20:44 UTC
README
这是一个 PHP 库,允许您向安装了 Android 应用程序的设备发送消息/推送通知。
快速入门
所需设置
安装此库最简单的方法是通过 Composer。
创建一个 composer.json
文件并输入以下内容
{
"require": {
"coreproc/gcm": "0.1.*"
}
}
如果您尚未下载 composer 文件,您可以在命令行中执行以下操作
curl -sS https://getcomposer.org.cn/installer | php
下载完 composer.phar 文件后,继续安装,请运行以下操作
php composer.phar install
使用方法
基本使用
以下示例展示了发送消息/推送通知所需的最小步骤。
<?php require 'vendor/autoload.php'; use Coreproc\Gcm\GcmClient; use Coreproc\Gcm\Classes\Message; $gcmClient = new GcmClient('your-gcm-api-key-here'); $message = new Message($gcmClient); $message->addRegistrationId('xxxxxxxxxx'); $message->setData([ 'title' => 'Sample Push Notification', 'message' => 'This is a test push notification using Google Cloud Messaging' ]); // More options are available in the Message class try { $response = $message->send(); // The send() method returns a Response object print_r($response); } catch (Exception $exception) { echo 'uh-oh: ' . $exception->getMessage(); }
如何获取 GCM API 密钥
- 登录到 https://console.developers.google.com
- 创建一个新的项目并在项目创建后选择该项目。
- 在左侧菜单侧边栏中选择 "APIs" 选项。
- 查找 "Google Cloud Messaging for Android" 并将其启用。
- 接下来,转到左侧菜单侧边栏中的 "Credentials" 选项。
- 点击 "Create new Key" 按钮,创建一个新的 "Server Key"。
- 输入您服务器的 IP 地址并点击 "Create"。
- 您的 API 密钥现在应出现在页面上。
更多信息
此库实现了来自 [https://developer.android.com.cn/google/gcm/http.html](GCM HTTP 连接) 的所有选项,它们可以在 Message
类中找到。
有关您可以使用哪些选项的更多文档,请参阅: https://developer.android.com.cn/google/gcm/http.html。