谷歌云消息推送通知

时间:2015-01-10 08:32:16

标签: android push-notification google-cloud-messaging

我可以在Google Chrome上使用POSTMAN客户端将有效内容消息发送到GCM服务器以进行测试。 其次,如果是,则要发送的header和url参数是什么。

3 个答案:

答案 0 :(得分:23)

是的,你可以。

1。发送带有JSON有效负载的通知

网址:https://android.googleapis.com/gcm/send

接头:

  • 授权:key =< your-api-key>
  • Content-Type:application / json

正文(点击'原始'标签):

{
  "collapse_key": "score_update",
  "time_to_live": 108,
  "delay_while_idle": true,
  "data": {
    "score": "4x8",
    "time": "15:16.2342"
  },
  "registration_ids":["4", "8", "15", "16", "23", "42"]
}

注意:registration_ids是唯一必填字段,其他所有字段都是可选字段。

2。发送带有纯文本负载的通知

网址:https://android.googleapis.com/gcm/send

接头:

  • 授权:key =< your-api-key>
  • 内容类型:application / x-www-form-urlencoded; charset = UTF-8

正文(点击“x-www-form-urlencoded”标签):

collapse_key=score_update
time_to_live=108
delay_while_idle=1
data.score=4x8
data.time=15:16.2342
registration_id=42

注意:registration_id是唯一必填字段,其他所有字段都是可选字段。


来源:https://developer.android.com/google/gcm/http.html

答案 1 :(得分:5)

仅仅是为了记录并从@Alexandru Rosianu完成了很好的答案,GCM端点改变了一段时间,建议使用新的。以下是官方文档中的一个示例:

验证

要发送消息,应用程序服务器会发出POST请求。例如:

https://gcm-http.googleapis.com/gcm/send

消息请求由两部分组成:HTTP标头和HTTP正文。

HTTP标头必须包含以下标头:

  • Authorization:key = YOUR_API_KEY
  • Content-Typeapplication/json代表JSON; application/x-www-form-urlencoded;charset=UTF-8用于纯文本。如果省略Content-Type,则假定格式为纯文本。

例如:

Content-Type:application/json
Authorization:key=YOUR_API_KEY

{
  "notification": {
      "title": "Portugal vs. Denmark",
      "text": "5 to 1"
  },
  "to" : "bk3RNwTe3H0:CI2k_H..."
}

HTTP正文内容取决于您使用的是JSON还是纯文本。有关JSON或纯文本消息可包含的所有参数的列表,请参阅the Server Reference

使用Curl的示例:

# curl --header "Authorization: key=YOUR_API_KEY" \
       --header Content-Type:"application/json" \
       https://gcm-http.googleapis.com/gcm/send \
       -d "{\"notification\": { \"title\": \"Portugal vs. Denmark\"," \
          "\"text\": \"5 to 1\" }, \"to\" : \"bk3RNwTe3H0:CI2k_H...\" }"

答案 2 :(得分:0)

是的,您可以使用POSTMAN。

此GCM通知测试工具通过减少您每次在POSTMAN中输入的项目数量,极大地简化了服务器端测试 - http://techzog.com/development/gcm-notification-test-tool-android/