gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:13:30 25 4
gpt4 key购买 nike

我正在开发 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com