当前位置:Gxlcms >
PHP教程 >
GCMwithPHP(GoogleCloudMessaging)云推送消息功能的例子
GCMwithPHP(GoogleCloudMessaging)云推送消息功能的例子
时间:2021-07-01 10:21:17
帮助过:6人阅读
<无详细内容>
- $url = 'https://android.googleapis.com/gcm/send';
- $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);
- ?>
|