4

我尝试将数据发送到 gcm 并在客户端接收它。一切正常,推送已接收,但提交的数据为空,请尝试像这样的邮递员:

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

标题:

Authorization: key=<your-api-key>
Content-Type: application/json

身体

{
  "collapse_key": "score_update",
  "time_to_live": 108,
  "delay_while_idle": true,
  "data": {
    "key1": "value1",
    "key2": "value2"
  },
  "registration_ids":["eaFbvFT64EQ:APA91bEfdq8QDTU2XbQ3V1bhC5UnMz2ZKWUQokq3Ta79Vg_2-Z8rnI6MFCxko6hVt3EoSQoqa24-ddjy8iSbxoP36rvXoGcPqsMQWFjzM5mz6K8tPbfoL2zEEfDxvcXajlb_-vw2vmpv"]
}

这种方式工作并使用registration_ids向客户端发送推送,但提交的数据为空。

并尝试用另一种方式代替这样的registration_ids:

{
     "to":"eaFbvFT64EQ:APA91bEfdq8QDTU2XbQ3V1bhC5UnMz2ZKWUQokq3Ta79Vg_2-Z8rnI6MFCxko6hVt3EoSQoqa24-ddjy8iSbxoP36rvXoGcPqsMQWFjzM5mz6K8tPbfoL2zEEfDxvcXajlb_-vw2vmpv",
     "data": {
    "key1": "value1",
    "key2": "value2"
  }
}

就像最后一种方式推送是接收空数据

我找到https://github.com/gauntface/simple-push-demo项目并实施它。这个项目工作得很好,但在这个项目中,有效载荷数据是这样加密的:

标题:

Authorization: key=<your-api-key>
Content-Type: application/json
Encryption: salt=L_da9h_5eIPS1c0gNV3fOQ
Crypto-Key: dh=BPDpQTlRDuk8DBFB3LxuTSnevgZGla7g8-LrTRSvUkPiU_ZsQVppocib1lFTYKP33bENL_gaMahaEXinMuYwu-c

身体

{
    "to":"fE5h8Q6gtno:APA91bEO-_LLDOIGMStAxR9J58RwA5fOSdvwVKNYkBnq7Xohm5kf-b4Gc4iq6BzrwEIgZxsKb3EKCtAsQgS34sKWpVEzX_gWx7OpCUuzKRqg50zOt2TjMR1KjHYwV3EkiE0BUh6JS-qu",
    "raw_data":"NBpw3QkilspdNClRE1k1CYsg1wHT3Q=="

}

问题 :

1-如何在不加密的情况下发送带有有效负载数据的 gcm 推送消息

to2 -param和 register_idsparam有什么区别

4

0 回答 0