我正在使用PHP发送Firebase通知,但未发送该消息。该通知似乎已经发送,但是没有发送。我再次尝试使用POSTMAN并达到了相同的结果。我想向所有用户发送通知。
<?php
define('API_ACCESS_KEY','xxxxxxxxxxxxxxxxxxxxxxx');
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$notification = [
'title' =>'TITLE',
'body' => 'MESSAGE.'
];
$extraNotificationData = ["message" => $notification,"moredata" =>'dd'];
$fcmNotification = [
'to' => "/topics/all",
'notification' => $notification,
'data' => $extraNotificationData
];
$headers = [
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$fcmUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
返回的数据
{"message_id":4709853598141003946}
答案 0 :(得分:0)
确保您的变量正确并且主题区分大小写,我将“ A”大写为“ all”,并且对我来说很好用。