Dies ist mein PHP-Skript und ich sende den Körper und die Titel-Strings von meiner Android-App. Hier kann ich den Nachrichtentext in meiner Benachrichtigung, aber nicht den Titel und auch wenn ich setzen; $message = array( 'message' => $body, 'title' => 'This is my title', 'sound' => 1 );
Wie kann ich den Titel meiner Push-Benachrichtigung in meinem PHP-Skript festlegen?
Dies funktioniert auch nicht.
<?php
$body = $_POST["body"];
$title = $_POST["title"];
$inc_phone = $_POST["inc_phone"];
function send_notification ($tokens,$message)
{
$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);
return $result;
}
//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"];
}
}
mysqli_close($conn);
$message = array(
'message' => $body,
'title' => $title,
'sound' => 1
);
$message_status = send_notification($tokens, $message);
echo $message_status;
?>
Hallo, Tarun. Konntest du es lösen? – JohnA10