Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. function sendGCM($registration_ids, $message) {
  2.  
  3.  
  4. // Set POST variables
  5. $url = 'https://android.googleapis.com/gcm/send';
  6.  
  7. $fields = array(
  8. 'registration_ids' => $registration_ids,
  9. 'data' => $message,
  10. );
  11.  
  12. $headers = array(
  13. 'Authorization: key=' . GOOGLE_API_KEY,
  14. 'Content-Type: application/json'
  15. );
  16. //print_r($headers);
  17. // Open connection
  18. $ch = curl_init();
  19.  
  20. // Set the url, number of POST vars, POST data
  21. curl_setopt($ch, CURLOPT_URL, $url);
  22.  
  23. curl_setopt($ch, CURLOPT_POST, true);
  24. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26.  
  27. // Disabling SSL Certificate support temporarly
  28. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  29.  
  30. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  31.  
  32. // Execute post
  33. $result = curl_exec($ch);
  34. if ($result === FALSE) {
  35. die('Curl failed: ' . curl_error($ch));
  36. }
  37.  
  38. // Close connection
  39. curl_close($ch);
  40. echo $result;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement