Как установить заголовок push-уведомлений в php-скрипте?

Я должен установить название push-уведомления. Я использую fcm для отправки push-уведомлений. Если я использую метод setContentTitle () для установки заголовка уведомления из приложения, это работает, но если я использую следующий код php ниже на моем сервере, это не работает. Пожалуйста, помогите мне

$inc_phone = $_POST["inc_phone"];

function send_notification ($tokens,$message,$title,$inc_name)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = AIzaSyAe9Qxx2URTyqXmf0mTheMq_ss_DOJaVQs ',
'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);
//Decoding json from result
$res = json_decode($result);//Getting value from success
$flag = $res->success;

//if success is 1 means message is sent
if($flag == 1){
echo "Notification sent from ".$message['title'] ." to ".$inc_name;
}else{
echo 'Notification was not sent why?';
}
}
//Connect to the database
$host = "127.0.0.1";
$user = "rajhanssingh";                     //Your Cloud 9 username
$pass = "";                                  //Remember, there is NO password by default!
$db = "fcm";                                  //Your database name you want to connect to
$port = 3306;                                //The port #. It is always 3306

$conn = mysqli_connect($host, $user, $pass, $db, $port);

//$conn = mysqli_connect("localhost","root","","fcm");
$sql = " Select token From utoken where phone_no='$inc_phone' ";
$result = mysqli_query($conn,$sql);
$tokens = array();
if(mysqli_num_rows($result) > 0 ){
while ($row = mysqli_fetch_assoc($result)) {
$tokens[] = $row["token"];
}
}

$q = " Select name From utoken where phone_no='$inc_phone' ";
$res_name = mysqli_query($conn,$q);
if(mysqli_num_rows($res_name) > 0 ){
while ($row = mysqli_fetch_assoc($res_name)) {
$name = $row["name"];
}
}

mysqli_close($conn);
$message = array(
'title' => $title,
'message' => $body
);
$message_status = send_notification($tokens, $message,$title,$name);
echo $message_status;
?>

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …