我正在开发一个向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);
好的,我找到了解决方案,使用collapse_key
$fields=json_encode(array('to'=>$to,"notification"=>$notification,"collapse_key"=>"new_messages"));
$notification= array(
'title'=>'Title',
'body' => 'Body',
'tag' => 'new_messages'
);