使用普通身份验证的unix c ++ app服务器没有从GCM xmpp ccs接收<success>

时间:2015-08-06 15:54:30

标签: android c++ unix xmpp google-cloud-messaging

我正在开发unix C ++通知应用服务器而不使用任何xmpp库。 我试图按照https://developers.google.com/cloud-messaging/ccs的步骤进行握手。我在ssl隧道上使用TLS协议。

我发送了以下内容给gcm.googleapis.com:5235 <stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'/>

我收到了以下来自gcm.googleapis.com:5235的两条消息作为回应 1. <stream:stream from="gcm.googleapis.com" id="60D46BF12BAF72D3" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"> 2. <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>

并且,我发送了以下消息作为回应。我尝试使用gloox的encode64代码。我也尝试使用内部Base64 :: encode_8bit。以下是TheWonderBird评论之后的修复但尚未成功。

stringstream key; 
key << '\0' << senderId << "@gcm.googleapis.com" << '\0' << apiKey; 
string hexkey = encode64(key.str()); 
stringstream auth; 
auth << "<auth mechanism='PLAIN' xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>" << hexkey << "</auth>"; 
string authStr = auth.str(); 
sslSock_->write(authStr.c_str(), authStr.length());

我原本希望从gcm.googleapis.com:5235收到<success>,但收到零字节,并从SSL_get_error函数调用中获取错误代码5。我不确定我在这里做错了什么,因为我正在遵循https://developers.google.com/cloud-messaging/ccs

的步骤

另外,我没有看到发送者ID的用途,因为步骤没有提到要在任何地方发送它。

有人可以指导我吗?请注意,我不允许使用任何xmpp库,我必须在Unix C ++中开发它。

2 个答案:

答案 0 :(得分:2)

<auth>内的字符串应该是base64编码的\0username\0password字符串,而不是您的API密钥。用户名为senderId@gcm.googleapis.com,密码是您的API密钥。我建议您了解有关XMPP和普通身份验证机制的更多信息,或使用现成的库。

答案 1 :(得分:1)

TheWonderBird的评论肯定有帮助。还有一件我必须做的修复。我发送了封闭的xml <stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'/>。相反,我应该发送<stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>。基本上,不要关闭流。

最终收到<success>