neatekFb

Send android notification messages to Firebase Messaging

Nov 11th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <?php
  2. // Vladimir Zhelnov - neatek.pw - Web/iOS dev
  3. // PushServer for Radiovera.ru
  4.  
  5. // Your Message
  6. $data = [
  7.     "to" => "/topics/push", // here is Topic (create in AndroidApp, or device token)
  8. // customizated notification message on override onMessageReceived Android App
  9.     "data" => [
  10.         "message" => "Привет мир",
  11.         "title" => "РАДИО ВЕРА"
  12.     ],
  13. // here is default notification without customization
  14. /*    "notification" => [
  15.       "body" => "Привет мир",
  16.       "title" => "РАДИО ВЕРА",
  17.       "icon" => "myicon",
  18.       "sound" => "default"
  19.     ]*/
  20. ];
  21.  
  22. // Process send that notification to users
  23. $data_string = json_encode( $data );
  24. $ch = curl_init('https://fcm.googleapis.com/fcm/send');
  25. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  26. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  27. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  28. curl_setopt($ch, CURLOPT_HTTPHEADER,
  29.     [
  30.         'Content-Type: application/json',
  31.         'Content-Length: ' . strlen($data_string),
  32.         'Authorization: key=HERE_IS_TOKEN_OF_FIREBASE_MESSAGING'
  33.     ]
  34. );
  35. $result = curl_exec($ch);
  36. var_dump($result);
Add Comment
Please, Sign In to add comment