Estoy tratando de enviar notificaciones PUSH a mi App desde un script PHP:
Código PHP:
<?php
define("GOOGLE_API_KEY", "Clave para las aplicaciones de navegador");
define("GOOGLE_GCM_URL", "https://android.googleapis.com/gcm/send");
$reg_id = "ID obtenido por la App";
$msg = "Hola";
send_gcm_notify($reg_id, $msg);
function send_gcm_notify($reg_id, $message) {
$fields = array(
'registration_ids' => array( $reg_id ),
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, GOOGLE_GCM_URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Problem occurred: ' . curl_error($ch));
}
curl_close($ch);
echo $result;
}
?>
{"multicast_id":8119445141225574726,"success":0,"f ailure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}
¿Alguien lo sabe solucionar?
Gracias.