$arrNotificationMessage = array(
'title'=>'Test',
'text'=>"Testing Notification",
'sound' => "mySound",
'priority'=>"high"
);
$extraData = array(
'any_extra_data' =>"any data"
);
$deviceToken = "User device FCM token id";
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header=array('Content-Type: application/json',
"Authorization: key=YOUR_KEY");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \"notification\": ".json_encode($notificationMessage).", \"data\":" . json_encode($extraData) . ", \"to\" : ".json_encode($deviceToken)."}");
$result = curl_exec($ch);
curl_close($ch);
if ($result === FALSE) {
//log_message("DEBUG", 'Curl failed: ' . curl_error($ch));
}
else{
$result = json_decode($result);
if($result->success ===1){
return true;
}
else{
return false;
}
}