使用node-xmpp在节点中编写Google CCS服务器时出错
这是编写CCS服务器的Google文档中的python代码:
https://developer.android.com/google/gcm/gs.html#server
我想出了大部分,以及如何使用JavaScript代码使用https://github.com/astro/node-xmpp
但是我无法理解如何使用模板发送数据,正是这部分代码:
def send(json_dict): template = ("<message><gcm xmlns='google:mobile:data'>{1}</gcm></message>") client.send(xmpp.protocol.Message( node=template.format(client.Bind.bound[0], json.dumps(json_dict))))
在node-xmpp中,发送是通过以下方式完成的:
var cl = new xmpp.Client({ jid: username, password: password }); cl.addListener('online', function() { argv.slice(5).forEach( function(to) { cl.send(new xmpp.Element('message', { to: to, type: 'chat'}). c('body'). t(argv[4])); });
我明白正在发送的JSON,但是我无法对他们在Python中pipe理的模板进行绑定。 任何帮助?
重要的部分是以所需格式发送消息:
<message id=""> <gcm xmlns="google:mobile:data"> { "to":"REGISTRATION_ID", // "to" replaces "registration_ids" "message_id":"m-1366082849205" // new required field "data": { "hello":"world", } "time_to_live":"600", "delay_while_idle": true/false } </gcm> </message>
如果您使用模板,则无关紧要。 我不知道python
或javascript
,但在python示例中的模板的目的似乎只是为了避免每次发送邮件时需要编写包装JSON的XML标记。 发送消息时可以将它们附加到JSON。