我正在開發一種向 Android 手機發送 FCM 通知的工具。我正在使用 Firebase 云訊息傳遞來執行此操作。我通過 PHP 和 CURL 發送通知。我希望所有通知都帶有相同的識別符號,因為每次發送它們時,都會生成一個新的,我希望它被替換。
/*PHP CURL*/
$to="TOKEN USER";
$apiKey="KEY APPLICATION";
$notification= array(
'title'=>'TITLE',
'body' => 'BODY',
/* HERE SHOULD I ADD THE ID? */
);
$ch = curl_init();
$url="https://fcm.googleapis.com/fcm/send";
$fields=json_encode(array('to'=>$to,"notification"=>$notification));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$headers = array();
$headers[] = 'Authorization: key ='.$apiKey;
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
uj5u.com熱心網友回復:
我已經嘗試添加這兩個選項,但它也不起作用。
$notification= array(
'title'=>'Title',
'body' => 'Body',
'channelId' => 'Channel',
'android_channel_id' => 'Channel'
);
uj5u.com熱心網友回復:
好的,我找到了解決方案,使用 collapse_key
$fields=json_encode(array('to'=>$to,"notification"=>$notification,"collapse_key"=>"new_messages"));
$notification= array(
'title'=>'Title',
'body' => 'Body',
'tag' => 'new_messages'
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/417132.html
標籤:
