GCM XMPP数据包中是否可以使用非字符串值?

2024-10-01 04:45:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个pythongcm服务器(白名单)可以很好地接收来自android应用程序的消息,直到我在数据包中包含除字符串以外的任何内容,在这种情况下,我只在服务器上获取字符串值。你知道吗

例如,我的客户机发送了一条消息,其中包含一个名为data的包,该包中添加了一个字符串和一个int,如下所示:

data.putString("MSG_ID", ALARM_ID);
data.putInt("AA", 1);

我的服务器读取并打印如下:

if gcm:
    gcm_json = gcm[0].getData()
    msg = json.loads(gcm_json)
    print msg

输出为:

{u'category': u'xxxAPPNAMExxxx', u'from': u'xxxxGCMID', u'data': {u'MSG_ID': u'alarm'}, u'message_id': u'1'}

Tags: 字符串服务器idjson应用程序消息内容data
1条回答
网友
1楼 · 发布于 2024-10-01 04:45:09

再读几遍之后,我发现了我在前几次通读中一定错过的东西:

public void send (String to, String msgId, Bundle data)

Send an upstream ("device to cloud") message. You can only use the upstream feature if your GCM implementation uses the XMPP-based Cloud Connection Server. The message will be queued if we don't have an active connection for the max interval.

Parameters to string identifying the receiver of the message. For GCM project IDs the value is SENDER_ID@gcm.googleapis.com. The SENDER_ID should be one of the sender IDs used in register(). msgId ID of the message. This is generated by the application. It must be unique for each message. This allows error callbacks and debugging. data key/value pairs to be sent. Values must be String—any other type will be ignored.

所以TLDR;只允许字符串。

相关问题 更多 >