[英]Set ID in FCM notification
我正在开发一种向 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);
我已经尝试添加这两个选项,但它也不起作用。
$notification= array(
'title'=>'Title',
'body' => 'Body',
'channelId' => 'Channel',
'android_channel_id' => 'Channel'
);
好的,我找到了解决方案,使用 collapse_key
$fields=json_encode(array('to'=>$to,"notification"=>$notification,"collapse_key"=>"new_messages"));
$notification= array(
'title'=>'Title',
'body' => 'Body',
'tag' => 'new_messages'
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.