我有数据通知,在某些设备上我总是收到它,在某些设备上,我只在应用程序运行时收到它,而在一台设备上我从未收到过它。
我将优先级设置为高,但没有任何变化,我不确定它写得是否正确,这是 php 代码
$naslovPoruke = "Пробна апликација";
$path_to_fcm = "https://fcm.googleapis.com/fcm/send";
$server_key =my_key_here";
$key = "/topics/sve";
$msg = array
(
'title' => $naslovPoruke,
'body' => $poruka,
'idObjave' => $idObjave,
'naslovObjave' => $naslovObjave,
'tekstObjave' => $tekstObjave,
);
$headers = array
(
'Authorization:key=' .$server_key,
'Content-Type:application/json'
);
//$fields = array
//(
// 'to' => $key,
// 'notification' => array('title'=>$naslovPoruke,'body'=>$poruka),
// 'data' => $msg
//);
$fields = array
(
'to' => $key,
'data' => $msg,
'priority'=>"high",
'ttl'=>"0"
);
$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,$headers);
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;
curl_close($curl_session);
?>
这也是 json 响应:
{
"to": "/topics/sve",
"data": {
"title": "pushuptitle",
"body": "pushupbody",
"idObjave": "linktoimage.jpg",
"naslovObjave": "apptitle",
"tekstObjave": "appbody"
},
"priority": "high",
"ttl": "0"}
{
"message_id": 6358638519123612486
}
我不确定为什么我在所有设备上都没有收到此消息?
您可以先检查是否在未收到通知的设备上启用了通知。