迁移到Firebase后,我测试了通过使用Firebase控制台发送通知的工作正常,但我需要每天通知特定时间,以便不使用Firebase控制台,而是使用我以前的cron作业每天发送通知。我将https://android.googleapis.com/gcm/send
更改为https://fcm.googleapis.com/fcm/send
,但我的设备未收到任何通知。如何在服务器端实现firebase云消息传递?
有什么办法解决这个问题吗?或者我错过了什么?我的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;
}
@McAwesomville从我读过的https://开头火力点。 google.com/docs/cloud-messaging/server#implementing-http-connection-server-protocol它表示要发送消息,应用程序服务器i发出POST请求。例如:'https.fcm.googleapis.com/fcm/send' – natsumiyu
@McAwesomville它对使用什么感到困惑:(但我会尝试它 – natsumiyu
我会尽量环顾四周,让我知道如果我找到东西:) :) –