【发布时间】:2022-01-19 11:09:39
【问题描述】:
我正在开发一种向 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);
【问题讨论】:
标签: php curl firebase-cloud-messaging android-notifications