如何解析 GCM 响应以使用 php 从服务器中删除无效的注册 ID [英] How to parse GCM respond to remove invalid registration id from server with php

查看:19
本文介绍了如何解析 GCM 响应以使用 php 从服务器中删除无效的注册 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 Google Cloud Messaging 的问题...

I got a question about Google Cloud Messaging...

我向谷歌发送了 3 个注册 ID 的 GCM,然后谷歌回复说其中 2 个注册 ID 已成功发送,一个没有发送,因为注册 ID 错误!

I send GCM to Google for 3 Registration IDs, then Google replies that 2 of the Registration IDs has been sent successfully and one not, because the Registration ID was wrong!

但是它没有告诉我哪个注册 ID 没有被发送...

But it doesn't tell me which Registration ID has not been sent...

现在我的问题是:如何解析 Google GCM 响应以获取尚未发送的注册 ID?Google 是否有 API 或其他东西,以便我可以给它multicat_id"并告诉我哪个注册 ID 有问题?

Now here's my question: how can I parse the Google GCM response to get that which Registration ID has not been sent? Does Google has an API or something so that I can give it "multicat_id" and it tells me which Registration ID had a problem?

非常感谢任何帮助,我很困惑:)

Any help would be so much appreciated, I'm just so confused :)

推荐答案

按顺序来:

假设你发送这个:

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

并从 Google 获得此回复:

And get this response from Google :

{ "multicast_id": 216,
  "success": 3,
  "failure": 3,
  "canonical_ids": 1,
  "results": [
    { "message_id": "1:0408" },
    { "error": "Unavailable" },
    { "error": "InvalidRegistration" },
    { "message_id": "1:1516" },
    { "message_id": "1:2342", "registration_id": "32" },
    { "error": "NotRegistered"}
  ]
}

这意味着您发送的第 3 个注册 ID (15) 无效,第 6 个 (42) 未注册.两者都应从您的数据库中删除.

This means that the 3rd registration ID that you sent (15) is invalid and the 6th (42) is not registered. Both should be removed from your DB.

这篇关于如何解析 GCM 响应以使用 php 从服务器中删除无效的注册 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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