SHARE
TWEET

send.php

michussj07 Jan 3rd, 2019 (edited) 8 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Michał
  5.  * Date: 2019-01-03
  6.  * Time: 15:39
  7.  */
  8.  
  9. define('SERVER_API_KEY', 'Legacy_Server_Key');
  10.  
  11. $tokens = ['xxx'];
  12.  
  13. $header= [
  14.     'Authorization: Key= ' . SERVER_API_KEY,
  15.     'Content-Type: Application/json'
  16. ];
  17.  
  18. $msg=[
  19.     'title'=> 'Test Notification',
  20.     'body' => '5 to 1',
  21.     'icon'=> 'icon.png',
  22.     'image' => 'd.png',
  23.     'click_action' => 'www.google.com',
  24. ];
  25.  
  26. $payload=[
  27.     'registration_ids' => $tokens,
  28.     'data' => $msg,
  29. ];
  30.  
  31. $curl = curl_init();
  32.  
  33. curl_setopt_array($curl, array(
  34.     CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
  35.     CURLOPT_RETURNTRANSFER => true,
  36.     CURLOPT_CUSTOMREQUEST => "POST",
  37.     CURLOPT_POSTFIELDS => json_encode($payload),
  38.     CURLOPT_HTTPHEADER => $header,
  39. ));
  40.  
  41. $response = curl_exec($curl);
  42. $err = curl_error($curl);
  43.  
  44. curl_close($curl);
  45.  
  46. if ($err) {
  47.     echo "cURL Error #:" . $err;
  48. } else {
  49.     echo $response;
  50. }
  51.  
  52.  
  53.  
  54. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top