I want to send the PUSH notification to the Multiple USERS through PHP script. When I run my script it shows the result successful, but on my device I am not getting any Notification.
But when I use the FCM console, I got the Notifications on my Device.
PHP script:
<?php
function send_notification ($tokens, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message,
'click_action' => ACTIVITY_CIRCULAR
);
$headers = array(
'Authorization:key = my key',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
$conn = mysqli_connect("connection set-up");
$sql = "Select FirebaseID From Coordinates";
$result = mysqli_query($conn,$sql);
$tokens = array();
//var_dump(result);
if(mysqli_num_rows($result) > 0 ){
while ($row = mysqli_fetch_assoc($result)) {
$tokens[] = $row["FirebaseID"];
}
}
var_dump($tokens);
mysqli_close($conn);
$message = array("message" => "Hello World");
$message_status = send_notification($tokens, $message);
echo $message_status;
?>
My result:
{"multicast_id":6386552330832519***,"success":2,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1477******764957%e8a8d907f9fd7ecd"},{"message_id":"0:1477293027764959%e8a8d907f9f***cd"}]}
EDIT : Is there any way to check where the message is failing because it shows the Successful in Result...but it doesn't reach to device