Advertisement
arijulianto

Send FCM Notif via PHP

Jul 24th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <?php
  2. function sendFCM($message, $receivers, $api_key){
  3.     $fields = array(
  4.         'registration_ids' => is_array($receivers) ? $receivers : [$receivers],
  5.         'data' => $message,
  6.     );
  7.     $headers = array('Authorization:key='.$api_key,'Content-Type:application/json');
  8.  
  9.     $ch = curl_init();
  10.     curl_setopt( $ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
  11.     curl_setopt( $ch, CURLOPT_POST, true);
  12.     curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
  13.     curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
  14.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  15.     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  16.     $result = curl_exec($ch);
  17.     curl_close($ch);
  18.     return $result;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement