迁移到Firebase后,我使用Firebase控制台测试发送通知功能,发现它可以正常工作。但是我需要在特定时间每天发送通知,所以我改用以前的cron job来实现每日通知的发送。我将 https://android.googleapis.com/gcm/send
更改为 https://fcm.googleapis.com/fcm/send
,但我的设备没有收到任何通知。
有没有什么解决方法?还是我漏了什么?我的cron job对于仍在使用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;
}