0
我試圖從PHP發送通知給Android應用程序。我的PHP代碼在這裏。PHP + Android CURL Firebase通知錯誤
<?php
require "int.php";
$message = $_POST['message'];
$title = $_POST['title'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "1:485869546397:android:bd503a78b6c26c35";
$sql = "select fcm_token from fcm_info";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_row($result);
$key = $row[0];
$headers = array(
'Authorization:key=' .$server_key,
'Content-Type:application/json'
);
$fields = array('to'=>$key,
'notification'=>array('title'=>$title,'body'=>$message));
$payload = json_encode($fields);
echo $payload;
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$result = curl_exec($curl_session);
echo $result;
?>
,我可以從火力控制檯發送通知。和服務器ID代碼是正確的。我不知道這是怎麼回事?你能給出一個建議或任何方式來解決這個問題?謝謝...
50x錯誤通常意味着問題出現在服務器端。您可以在此處提出問題:https://firebase.google.com/support/ – pawelo
您所獲得的下游消息響應正文不包含[documentation](https://firebase.google)中定義的一些字段.com/docs/cloud-messaging/http-server-ref#interpret-downstream),所以最好按照@pawelo的建議與Firebase支持部門聯繫 – GeorgeLBA