Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. function sendGCM($message, $registration_ids) {
  2. //FCM URL
  3. $url = "https://fcm.googleapis.com/fcm/send";
  4. //prepare data
  5. $fields = array (
  6. 'registration_ids' => array ($registration_ids),
  7. 'data' => array ("message" => $message)
  8. );
  9. $fields = json_encode ( $fields );
  10.  
  11. //header data
  12. $headers = array ('Authorization: key=<YOUR_API_KEY>', 'Content-Type: application/json');
  13.  
  14. //initiate curl request
  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_POSTFIELDS, $fields );
  21.  
  22. // execute curl request
  23. $result = curl_exec ( $ch );
  24.  
  25. //close curl request
  26. curl_close ( $ch );
  27.  
  28. //return output
  29. return $result;
  30.  
  31. "multicast_id": 5359746182596118281,
  32. "success": 0,
  33. "failure": 1,
  34. "canonical_ids": 0,
  35. "results": [
  36. {
  37. "error": "InvalidRegistration"
  38. }
  39. ]
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement