Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <?php
  2. // API access key from Google API's Console
  3. define( 'API_ACCESS_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' );
  4. // set only for one for safety
  5. $registrationId = $_GET['id'];
  6. $texto = $_GET['texto'];
  7. // prep the bundle
  8. $msg = array
  9. (
  10. 'title' => 'Notificação',
  11. 'body' => $texto,
  12. 'icon' => 'myicon',
  13. 'sound' => 'default'
  14. );
  15. $fields = array
  16. (
  17. 'priority' => 'high',
  18. 'to' => $registrationId,
  19. 'notification' => $msg
  20. );
  21. $headers = array
  22. (
  23. 'Authorization: key=' . API_ACCESS_KEY,
  24. 'Content-Type: application/json'
  25. );
  26.  
  27. $ch = curl_init();
  28. curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
  29. curl_setopt( $ch,CURLOPT_POST, true );
  30. curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
  31. curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
  32. curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
  33. curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
  34. $result = curl_exec($ch );
  35. curl_close( $ch );
  36. echo $result;
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement