kongkannika/google-cloud-messaging-php

该包的最新版本(dev-master)没有可用的许可证信息。

将推送通知发送到Google Cloud Messaging PHP(用于Android)

dev-master 2015-09-30 06:52 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:21:23 UTC


README

使用PHP将推送通知发送到Android设备。

如何使用?

  • 向多个设备推送消息
<?php
	include_once 'GoogleCloudMessaging.php';
	$registerationIds = array(
		'APA91bH-lf7YXuGvkD1-iCtcgSr4vrWbqkxIz1idD_VGzcLiUSqJd...',
		'APA91bFUvwEtgOMQcqXVn06jheApvsZAQ2KSsZrPQSdRzO5eadU4E...',
		'APA91bGZT_5uyha9nRnWZnUf6OcL_c971Pd4ckAceQPfJ3b57NhhC...',
		//...
	);
	$data = array(
		'id' => 1000,
		'message' => "Hello Android! You've got a message from me ^_^",
		'url' => 'http://www.google.com',
		//...
	);
	$gcm = new GoogleCloudMessaging('GCM_API_KEY');
	$gcm->pushMessageToManyDevices($registerationIds, $data);
?>
  • 向单个设备推送消息
<?php
	include_once 'GoogleCloudMessaging.php';
	$registerationId = 'APA91bH-lf7YXuGvkD1-iCtcgSr4vrWbqkxIz1idD_VGzcLiUSqJd...';
	$data = array(
		'id' => 1000,
		'message' => "Hello Android! You've got a message from me ^_^",
		'url' => 'http://www.google.com',
		//...
	);
	$gcm = new GoogleCloudMessaging('GCM_API_KEY');
	$gcm->pushMessageToOneDevice($registerationId, $data);
?>

如何获取API密钥?

https://developer.android.com.cn/google/gcm/gs.html

完成!