Advertisement
vergepuppeter

Firebase Notification

Feb 24th, 2016
2,183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1. <?php
  2.  
  3. define( 'API_ACCESS_KEY', 'AIza......Xhdsnkf' ); // get API access key from Google/Firebase API's Console
  4.  
  5. $registrationIds = array( 'cyMSGTKBzwU:APA.....gyfgdshjbfhsdgbhbhsdf' ); //Replace this with your device token
  6.  
  7.  
  8. // Modify payload here
  9. $msg = array
  10. (
  11.             'mesgType'      => 'ACTION', //Must be COM or MEM
  12.             'action_id'     => '4664'
  13. );
  14.  
  15. $notification = array  //refer payload notification here : https://firebase.google.com/docs/cloud-messaging/http-server-ref
  16. (
  17.             'title'      => 'New Action has created', //Must be COM or MEM
  18.             'body'     => 'Come meet me at Bangsar South',
  19.             'sound'         => 'default'
  20.                
  21. );
  22.  
  23. $fields = array
  24. (
  25.         'registration_ids'      => $registrationIds,
  26.         'data'                  => $msg,
  27.         'notification'          => $notification
  28. );
  29.  
  30. $headers = array
  31. (
  32.         'Authorization: key=' . API_ACCESS_KEY,
  33.         'Content-Type: application/json'
  34. );
  35.  
  36. $ch = curl_init();
  37. curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' ); //For firebase, use https://fcm.googleapis.com/fcm/send
  38.  
  39. curl_setopt( $ch,CURLOPT_POST, true );
  40. curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
  41. curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
  42. curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
  43. curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
  44. $result = curl_exec($ch );
  45. curl_close( $ch );
  46. echo $result;
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement