Advertisement
Guest User

Untitled

a guest
May 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. public function sendNotification($registrationIds,$title,$message)
  2.     {
  3.         $msg = array
  4.         (
  5.             'body' => $message,
  6.             'title'     => $title,
  7.             'vibrate'   => 1,
  8.             'sound'     => 'default',
  9.             'largeIcon' => 'large_icon',
  10.             'smallIcon' => 'small_icon'
  11.         );
  12.         $fields = array
  13.         (  
  14.             //in array ['23143252','329AJK398420380]
  15.             'registration_ids'  => $registrationIds,
  16.             'notification'          => $msg
  17.         );
  18.        
  19.         $headers = array
  20.         (  
  21.             //server-key firebase
  22.             'Authorization: key=' . config('firbase.server_key'),
  23.             'Content-Type: application/json'
  24.         );
  25.        
  26.         $ch = curl_init();
  27.         curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
  28.         curl_setopt( $ch,CURLOPT_POST, true );
  29.         curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
  30.         curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
  31.         curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
  32.         curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
  33.         $result = curl_exec($ch );
  34.         curl_close( $ch );
  35.  
  36.         return $result;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement