Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <?php
  2.  
  3. $json_data = array(
  4. 'to' => 'dRbCRkw774Y:APA91bEXSfFnm-1bJzgECCGEK9ImhS40ZjG7wzyTA2e4pUKxtCx_lW5B2oriTCwqQfB1-TJaGWs3lN-OpCuAErrUW3szyFLgasCZfAvGCJ_y_BEWDWcw4PfvRLv9sHdk8qPk2Oa3Mht8',
  5. 'notification' => array(
  6. 'body' => 'something',
  7. 'title' => 'something',
  8. ),
  9. 'data' => null,
  10. );
  11.  
  12. // print(json_encode($json_data));
  13.  
  14. $data = json_encode($json_data);
  15. //FCM API end-point
  16. $url = 'https://fcm.googleapis.com/fcm/send';
  17.  
  18. //api_key in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key
  19. $server_key = 'AAAAQGz59Vw:APA91bE-arA2TUKPFw3Lsk2_PaesNhoWAZfpmFxVfijUrpS3d6OmuBKBZZfV-JhGDFQNEjN2_4VxG8qbgQXBBD8HviFEqyh4FUTWp-0EiqI3uhh7unk4jISYMSSq77ndG8uB3bAPxO0c';
  20. //header with content_type api key
  21. $headers = array(
  22. 'Content-Type:application/json',
  23. 'Authorization:key=' . $server_key
  24. );
  25. //CURL request to route notification to FCM connection server (provided by Google)
  26. $ch = curl_init();
  27. curl_setopt($ch, CURLOPT_URL, $url);
  28. curl_setopt($ch, CURLOPT_POST, true);
  29. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  30. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  31. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  32. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  33. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  34. $result = curl_exec($ch);
  35. if ($result === FALSE) {
  36. die('Oops! FCM Send Error: ' . curl_error($ch));
  37. }
  38. curl_close($ch);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement