Android: Prueba de notificaciones Push en línea (Google Cloud Messaging) [cerrado]


Actualizar: GCM {[5] } está en desuso, use FCM

Estoy implementando Google Cloud Messaging en mi aplicación. El código del servidor no está listo todavía y en mi entorno debido a algunas restricciones de firewall no puedo implementar un servidor de prueba para notificaciones push. Lo que estoy buscando es un servidor en línea que envíe algunas notificaciones de prueba a mi dispositivo para probar la implementación de mi cliente.

Author: Adnan, 2014-03-04

4 answers

Encontré una manera muy fácil de hacer esto.

Abierto http://phpfiddle.org /

Pegue el siguiente script php en el cuadro. En php script set API_ACCESS_KEY, establece id de dispositivo separados por coma.

Presione F9 o haga clic en Ejecutar.

Diviértete;)

<?php


// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );


$registrationIds = array("YOUR DEVICE IDS WILL GO HERE" );

// prep the bundle
$msg = array
(
    'message'       => 'here is a message. message',
    'title'         => 'This is a title. title',
    'subtitle'      => 'This is a subtitle. subtitle',
    'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',
    'vibrate'   => 1,
    'sound'     => 1
);

$fields = array
(
    'registration_ids'  => $registrationIds,
    'data'              => $msg
);

$headers = array
(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
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 );
curl_close( $ch );

echo $result;
?>

Nota: Al crear la clave de acceso API en Google developer console, debe usar 0.0.0.0/0 como dirección ip. (Para fines de prueba).

Editar:

En caso de recibir un Registro no válido respuesta del servidor GCM, verifique la validez de su token de dispositivo. Puede verificar la validez de su token de dispositivo utilizando la siguiente url:

Https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=YOUR_DEVICE_TOKEN

Algunos códigos de respuesta:

Lo siguiente es la descripción de algunos códigos de respuesta que puede recibir del servidor.

{ "message_id": "XXXX" } - success
{ "message_id": "XXXX", "registration_id": "XXXX" } - success, device registration id has been changed mainly due to app re-install
{ "error": "Unavailable" } - Server not available, resend the message
{ "error": "InvalidRegistration" } - Invalid device registration Id 
{ "error": "NotRegistered"} - Application was uninstalled from the device
 165
Author: Adnan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-11 14:47:48

POSTMAN: Una extensión de Google chrome

Utilice postman para enviar mensajes en lugar de server. Los ajustes de Postman son los siguientes:

Request Type: POST

URL: https://android.googleapis.com/gcm/send

Header
  Authorization  : key=your key //Google API KEY
  Content-Type : application/json

JSON (raw) :
{       
  "registration_ids":["yours"],
  "data": {
    "Hello" : "World"
  } 
}

En el éxito obtendrá

Response :
{
  "multicast_id": 6506103988515583000,
  "success": 1,
  "failure": 0,
  "canonical_ids": 0,
  "results": [
    {
      "message_id": "0:1432811719975865%54f79db3f9fd7ecd"
    }
  ]
}
 155
Author: Michael,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-26 15:36:33

Pushwatch es un probador de notificaciones push de GCM y APNS en línea de uso gratuito desarrollado por mí mismo en Django/Python, ya que me he encontrado en una situación similar mientras trabajaba en múltiples proyectos. Puede enviar notificaciones GCM y APNS y también admite mensajes JSON para argumentos adicionales. Los siguientes son los enlaces a los probadores.

Por favor, hágamelo saber si tiene alguna preguntas o enfrentar problemas al usarlo.

 18
Author: Amyth,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-08 15:07:41

Postman es una buena solución y también lo es php fiddle. Sin embargo, para evitar poner la URL de GCM y la información del encabezado cada vez, también puede usar esta ingeniosa Herramienta de prueba de notificación de GCM

 6
Author: Varun,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-18 13:55:13