albaraam/php-gcm

一个用于通过Google Cloud Messaging向注册设备发送消息的PHP库

v1.0.0 2015-12-08 14:44 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:09:44 UTC


README

一个用于通过Google Cloud Messaging向注册设备发送消息的PHP库。

安装

安装此扩展的首选方法是使用composer

运行以下命令:

composer require albaraam/php-gcm "~1.0.0"

或者将以下内容添加到您的composer.json文件中的require部分:

"albaraam/php-gcm": "~1.0.0"

require

用法

use albaraam\gcm\GCMNotification;
use albaraam\gcm\GCMMessage;
use albaraam\gcm\GCMClient;

$notification = new GCMNotification("Title","Body");
$notification
	->setIcon("noti")
	->setSound("water.mp3");
.....

$message = new GCMMessage($notification, "ids"); // "ids" parameter can contain a array/single registration token or a topic key
$message
	->setData(['foo'=>'bar', 'baz'=>[1,2,3]])
	->setCollapseKey("collapse-key-1");
.....

$gcm = new GCMClient("YOUR_API_KEY"); 
$response = $gcm->send($message);

var_dump($response);