Advertisement
rusday14

firebase

Nov 26th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. <?php
  2. function send_notification ($tokens, $message)
  3. {
  4.  $url = 'https://fcm.googleapis.com/fcm/send';
  5.  
  6.  $msg = array
  7.  (
  8.  'body' => "$message",
  9.  'title' => "PUSH NOTIFICATION"
  10.  );
  11.  $fields = array
  12.  (
  13.  'registration_ids' => $tokens,
  14.  'notification' => $msg
  15.  );
  16.  $headers = array(
  17.  'Authorization:key = Your_AUTH_KEY_FIND_FROM_FIREBASE_CONSOLE',
  18.  'Content-Type: application/json'
  19.  );
  20.  
  21.  $ch = curl_init();
  22.  curl_setopt($ch, CURLOPT_URL, $url);
  23.  curl_setopt($ch, CURLOPT_POST, true);
  24.  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  25.  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26.  curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);  
  27.  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  28.  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  29.  $result = curl_exec($ch);          
  30.  if ($result === FALSE) {
  31.  die('Curl failed: ' . curl_error($ch));
  32.  }
  33.  curl_close($ch);
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement