首页 >后端开发 >php教程 >GCM with PHP (Google Cloud Messaging)云推送消息功能的例子

GCM with PHP (Google Cloud Messaging)云推送消息功能的例子

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-07-25 08:47:29849浏览
  1. $url = 'https://android.googleapis.com/gcm/send';
  2. $serverApiKey = "YOUR API KEY AS GENERATED IN API CONSOLE";
  3. $reg = "DEVICE REGISTRATION ID";
  4. $data = array(
  5. 'registration_ids' => array($reg),
  6. 'data' => array('yourname' => 'Joe Bloggs'));
  7. print(json_encode($data));
  8. $client = new Zend_Http_Client($url);
  9. $client->setMethod('POST');
  10. $client->setHeaders(array("Content-Type" => "application/json", "Authorization" => "key=" . $serverApiKey));
  11. $client->setRawData(json_encode($data));
  12. $request = $client->request('POST');
  13. $body = $request->getBody();
  14. $headers = $request->getHeaders();
  15. print("");var_dump($body);var_dump($headers);
  16. ?>
复制代码


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
上一篇:5 下一篇:将数组保存为文件