首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android:在线测试推送通知(Google Cloud Messaging)

Android:在线测试推送通知(Google Cloud Messaging)
EN

Stack Overflow用户
提问于 2014-03-04 18:08:22
回答 4查看 116.6K关注 0票数 97

更新: GCM已弃用,请使用FCM

我正在我的应用程序中实现Google Cloud Messaging。服务器代码还没有准备好,在我的环境中,由于一些防火墙的限制,我不能为推送通知部署测试服务器。我正在寻找的是一个在线服务器,它将发送一些测试通知到我的设备,以测试我的客户端实现。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-03-04 18:32:14

找到了一种非常简单的方法来做到这一点。

打开http://phpfiddle.org/

将下面的php脚本粘贴到框中。在php脚本set API_ACCESS_KEY中,设置用coma分隔的设备ids。

按F9键或单击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;
?>

对于FCM,google url是:https://fcm.googleapis.com/fcm/send

对于FCM v1,谷歌url为:https://fcm.googleapis.com/v1/projects/YOUR_GOOGLE_CONSOLE_PROJECT_ID/messages:send

注意:在google开发者控制台创建API访问密钥时,ip地址必须使用0.0.0.0/0。(用于测试目的)。

如果收到来自GCM服务器的无效注册响应,请交叉检查您的设备令牌的有效性。您可以使用以下url检查设备令牌的有效性:

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

一些响应码:

以下是服务端可能收到的一些响应码的说明。

{ "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
票数 168
EN

Stack Overflow用户

发布于 2015-06-11 18:46:07

POSTMAN : google chrome扩展

使用邮递员代替服务器发送消息。邮递员设置如下:

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

在成功的时候,你会得到

Response :
{
  "multicast_id": 6506103988515583000,
  "success": 1,
  "failure": 0,
  "canonical_ids": 0,
  "results": [
    {
      "message_id": "0:1432811719975865%54f79db3f9fd7ecd"
    }
  ]
}
票数 159
EN

Stack Overflow用户

发布于 2016-03-08 23:07:42

Pushwatch是一个免费的在线GCM和APNS推送通知测试器,这是我自己用Django/Python开发的,因为我发现自己在多个项目中也遇到了类似的情况。它可以发送GCMAPNS通知,还支持额外参数的JSON消息。以下是指向测试人员的链接。

如果您在使用它时有任何问题或遇到问题,请让我知道。

票数 19
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22168819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档