如何使用C++-XMPP握手将XMPP消息节格式化为GCM

How to format XMPP message stanza to GCM using C++ - xmpp handshake

本文关键字:消息 格式化 GCM XMPP 何使用 C++-XMPP      更新时间:2023-10-16

握手完成,并从GCM-xmpp连接接收到<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>。现在,我正在格式化并发送从APP服务器到GCM的发送到同步消息,以发送到移动设备,如下

ostringstream sync;
sync << "<message id="1234">";
sync << "<gcm xmlns="google:mobile:data">";
sync << " { ";
sync << ""to":"eA_hcHITvwo:APA91bEB83Gci",";
sync << " "message_id":"1234",";
sync << " "time_to_live":" << 10;
sync << " } ";
sync << "</gcm></message>";
string msg = sync.str();
sslSock_->write(msg.c_str(), msg.length());
std::string syncResp = readFromGcm(); // ack/nack

不幸的是,SSL套接字正在关闭,并且没有收到ack。知道吗,我在这里做错了什么?

我试图发送的实际消息如下

Sending msg=<message id="150827111504042682"><gcm xmlns="google:mobile:data"> { "to":"eA_hcHITvwo:APA91bEB83Gci", "message_id":"150827111504042682", "time_to_live":10 } </gcm></message>

在收到GCM的成功消息后,在发送任何节之前,我需要发送任何ack吗?或者我需要在大括号和名称值对之后添加换行符吗?

信息流 Sent1: <stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'> Received1: <stream:stream from="gcm.googleapis.com" id="EBA37684C852364D" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"> Received2: <stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features> Sent2: <auth mechanism='PLAIN' xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>ADM2NTU4MjFZVV0F1LVJV</auth> Received3: <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/> Sent3: <message id=""><gcm xmlns="google:mobile:data">{"to":"eA_hcHITvwo:APA91bEB83Gci","message_id":"150827161659237590","data":{"title":"Alert: mydata","text":"mydata refresh"},"time_to_live":10,"delay_while_idle":true,"delivery_receipt_requested":true}</gcm></message> Received4: None. Socket closed

我刚刚注意到设备令牌(eA_hcHITvwo:APA91bEB83Gci(中有冒号?我需要把它转换成某种东西吗?这样谷歌xmpp处理器就不会和json冒号("to":"deviceToken"(混淆了?

末尾缺少一个逗号

sync << "'to':'eA_hcHITvwo:APA91bEB83Gci'";

它应该是这样才有效:

sync << "'to':'eA_hcHITvwo:APA91bEB83Gci',";

也许这能解决你的问题。

最后我从https://developers.google.com/cloud-print/docs/rawxmpp和http://grokbase.com/p/gg/android-gcm/13a2zrnn34/gcm-ccs-xmpp-3rd-party-server-implementation

xmpp握手的另一个例子https://tech.yandex.com/disk/doc/dg/concepts/xmpp_xmpp-connection-docpage/

谢谢李的提问。不幸的是,目前还不清楚是谁回答的,但非常感谢最终回答的人。不确定为什么协议没有记录在正确的地方。

C (authenticate): <stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'> <auth mechanism='PLAIN' xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>base64Enc([userName][password])</auth> S: <stream:stream from="gcm.googleapis.com" id="352584B87B657F7F" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"> <stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features> <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/> C (pre Binding): <stream:stream to='gcm.googleapis.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'> S: <stream:stream from="gcm.googleapis.com" id="7C0C770AED97331C" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"> <stream:features><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features> C: (bind): <iq type='set' id='bind-1' to='gcm.googleapis.com'> <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'> <resource>core</resource> </bind> </iq> S: <iq from="gcm.googleapis.com" id="bind-1" type="result"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>[senderID]@gcm.googleapis.com/coreAB8CB2E7</jid></bind></iq> C: (session request): <iq to='gcm.googleapis.com' type='set' id='sess_1'> <session xmlns='urn:ietf:params:xml:ns:xmpp-session'/> </iq> S: single byte message and then S: <iq from="gcm.googleapis.com" type="result" id="sess_1"/> C: first stanza sent successfully