cron ジョブを使用して通知を送信しようとしています。GCM から FCM に移行しました。私のサーバー側では、変更し、データを に変更するhttps://android.googleapis.com/gcm/send to https://fcm.googleapis.com/fcm/send
ように要求する方法も更新しました。渡されたjsonを確認すると、有効なjsonですが、エラーが発生しています。とにかくこれを解決する方法はありますか?registration_ids
to
Field "to" must be a JSON string
これが私のコードです
function sendNotificationFCM($apiKey, $registrationIDs, $messageText,$id) {
$headers = array(
'Content-Type:application/json',
'Authorization:key=' . $apiKey
);
$message = array(
'to' => $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;
}