gpt4 book ai didi

android - 如何在服务器端实现 firebase 云消息传递?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:57:08 24 4
gpt4 key购买 nike

迁移到 Firebase 后,我测试了使用 firebase 控制台发送通知,它工作正常,但我需要在特定时间每天发送通知,所以我没有使用 firebase 控制台,而是使用我以前的 cron 作业每天发送通知。我将 https://android.googleapis.com/gcm/send 更改为 https://fcm.googleapis.com/fcm/send 但我的设备没有收到任何通知。

有什么办法可以解决吗?或者我错过了什么?我的 cron 作业在我仍在使用 GCM 的设备上运行良好。

这是我的代码

function sendNotificationFCM($apiKey, $registrationIDs, $messageText,$id) {


$headers = array(
'Content-Type:application/json',
'Authorization:key=' . $apiKey
);

$message = array(
'registration_ids' => $registrationIDs,
'data' => array(
"message" => $messageText,
"id" => $id,
),
);


$ch = curl_init();

curl_setopt_array($ch, array(
CURLOPT_URL => 'https://fcm.googleapis.com/fcm/send',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode($message)
));

$response = curl_exec($ch);
curl_close($ch);

return $response;
}

最佳答案

我在我的 json 中添加了 notification 对象。我发现在我的 remoteMessage.getNotification().getBody() 中它返回 null,这就是它没有收到我的 cron 发送的任何通知的原因。

编辑

这是我的 json 对象

$message = array(
'registration_ids' => $registrationIDs,
'notification' => array(
"title" => $id,
"body" => $messageText,
"icon" => "name_of_icon" ),
'data' => array(
"message" => $messageText,
"id" => $id,
),
);

关于android - 如何在服务器端实现 firebase 云消息传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37454822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com