android - 使用普通身份验证的 unix C++ 应用程序服务器未从 GCM xmpp ccs 接收到 <success>

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

我正在开发 unix C++ 通知应用程序服务器并且不使用任何 xmpp 库。 我正在尝试按照 https://developers.google.com/cloud-messaging/ccs 中的步骤操作握手。我在 ssl 隧道上使用 TLS 协议(protocol)。

我将以下内容发送到 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());

我期待收到 <success>来自 gcm.googleapis.com:5235,但收到零字节,并从 SSL_get_error 函数调用中获取错误代码 5。我不确定我在这里做错了什么,因为我正在按照 https://developers.google.com/cloud-messaging/ccs 中的步骤操作

另外,我看不出 sender-id 有什么用,因为步骤中没有提到它要发送到任何地方。

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

最佳答案

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

关于android - 使用普通身份验证的 unix C++ 应用程序服务器未从 GCM xmpp ccs 接收到 <success>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31860400/

相关文章:

android - 检测应用程序是否从华为应用市场安装

Android Listview 回收是带动画行的

c++ - 为 VS 2010 (MSVC 10) 编译的 libcurl 二进制文件

c++ - qt 定期检查 QProcess 状态

c++ - 如何在 C++ 中读取 MNIST 数据?

unix - 为什么有用户上下文和内核上下文... unix

php - php的random_int()函数分布

android - OpenGL-ES:如何在触摸坐标处设置对象?

android - createBitmap(int width, int height, Bitmap.Config config) 如何填充Bitmap?

python - 如何从文件中保存数据而不是在 Python 中的变量或列表中?