安卓:测试推送在线通知(谷歌云消息传递) [英] Android: Test Push Notification online (Google Cloud Messaging)

查看:219
本文介绍了安卓:测试推送在线通知(谷歌云消息传递)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现谷歌云消息传递在我的应用程序。服务器code是还没有准备好,在我的环境中,由于一些防火墙的限制,我不能部署一个测试服务器进行推送通知。我所寻找的是这会发送一些测试通知到我的设备来测试我的客户端实现一个在线服务器。

I am implementing Google Cloud Messaging in my application. Server code is not ready yet and in my environment due to some firewall restrictions I can not deploy a test sever for push notification. What I am looking for is a online server which would send some test notifications to my device to test my client implementation.

推荐答案

发现一个很简单的方法来做到这一点。

Found a very easy way to do this.

打开 http://phpfiddle.org/

粘贴下面的方框中的PHP脚本。在PHP脚本集API_ACCESS_KEY,设置设备ID相隔昏迷。

Paste following php script in box. In php script set API_ACCESS_KEY, set device ids separated by coma.

preSS F9或单击运行。

Press F9 or click Run.

有乐趣;)

<?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;
?>

注:在创建的谷歌开发者控制台API访问密钥,你必须使用0.0.0.0/0作为IP地址。 (用于测试目的)。

Note: While creating API Access Key on google developer console, you have to use 0.0.0.0/0 as ip address. (For testing purpose).

编辑:

在的情况下接收来自GCM服务器无效注册的响应,请交叉检查设备令牌的有效性。您可以使用以下网址检查设备令牌的有效性:

In case of receiving invalid Registration response from GCM server, please cross check the validity of your device token. You may check the validity of your device token using following url:

<一个href="https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=YOUR_DEVICE_TOKEN">https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=YOUR_DEVICE_TOKEN

有些反应codeS:

以下是一些应对codeS,你可能会收到来自服务器的说明。

Following is the description of some response codes you may receive from server.

{ "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

这篇关于安卓:测试推送在线通知(谷歌云消息传递)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆