Bupycnet

Untitled

Jul 13th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. function sendPushNotificationToGCM($registatoin_ids, $message) {
  2. //Google cloud messaging GCM-API url
  3. //$url = 'https://android.googleapis.com/gcm/send';
  4. $url = 'https://gcm-http.googleapis.com/gcm/send';
  5. $fields = array(
  6. 'registration_ids' => $registatoin_ids,
  7. 'data' => $message,
  8. );
  9. // Google Cloud Messaging GCM API Key
  10. define("GOOGLE_API_KEY", "KEY");
  11. $headers = array(
  12. 'Authorization: key=' . GOOGLE_API_KEY,
  13. 'Content-Type: application/json'
  14. );
  15. $ch = curl_init();
  16. curl_setopt($ch, CURLOPT_URL, $url);
  17. curl_setopt($ch, CURLOPT_POST, true);
  18. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  20. curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
  21. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  22. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  23. $result = curl_exec($ch);
  24. if ($result === FALSE) {
  25. die('Curl failed: ' . curl_error($ch));
  26. }
  27. curl_close($ch);
  28. return $result;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment