heHe intentado mil formas de hacer el post con php a la api de firebase cloud messagingfirebase cloud messaging
, y siempre recibo un "JSON_PARSING_ERRORerror: Unexpected token END OF FILE at position 0.\n", aquí
JSON_PARSING_ERROR: Unexpected token END OF FILE at position 0.\n
Aquí adjunto el código.:
$json_data = array(
"to" => $mobileToken,
"notification" => array(
"title" => "¡Hoy toca entrenar!",
"body" => "Consulta aquí el plan de hoy, Runneante."
)
);
$data = json_encode($json_data);
$url = 'https://fcm.googleapis.com/fcm/send';
$server_key = 'XXXXX no la muestrp';
$headers = array(
'Content-Type:application/json',
'Authorization:key='.$server_key
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
if ($result === FALSE) {
die('Oops! FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
$json_data = array(
"to" => $mobileToken,
"notification" => array(
"title" => "¡Hoy toca entrenar!",
"body" => "Consulta aquí el plan de hoy, Runneante."
)
);
$data = json_encode($json_data);
$url = 'https://fcm.googleapis.com/fcm/send';
$server_key = 'XXXXX no la muestrp';
$headers = array(
'Content-Type:application/json',
'Authorization:key='.$server_key
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
if ($result === FALSE) {
die('Oops! FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);