利用Google Cloud Messaging可以很方便的发送消息到手机客户端。
客户端连接Google服务器需要注册ID。
PHP相关代码如下:
- $url = '';
- $serverApiKey = "YOUR API KEY AS GENERATED IN API CONSOLE";
- $reg = "DEVICE REGISTRATION ID";
- $data = array(
- 'registration_ids' => array($reg),
- 'data' => array('yourname' => 'Joe Bloggs')
- );
- print(json_encode($data));
- $client = new Zend_Http_Client($url);
- $client->setMethod('POST');
- $client->setHeaders(array("Content-Type" => "application/json", "Authorization" => "key=" . $serverApiKey));
- $client->setRawData(json_encode($data));
- $request = $client->request('POST');
- $body = $request->getBody();
- $headers = $request->getHeaders();
- print("");
- var_dump($body);
- var_dump($headers);
阅读(2613) | 评论(0) | 转发(0) |