我是 gcm 上游消息传递的新手。我正在尝试通过 xmpp 连接到云连接服务器(使用 c# agsxmpp 库)。但是,我从服务器收到一条未经授权的错误消息,并且即使相同的项目编号/api 密钥适用于 http 下游推送通知,连接也会立即关闭。任何帮助表示赞赏。
这是代码。
var username = Configuration.PROJECT_NUMBER + "@" + Configuration.GCM_SERVER;
xmpp = new XmppClientConnection
{
UseSSL = true,
UseStartTLS = false,
Server = Configuration.GCM_SERVER,
ConnectServer = Configuration.GCM_SERVER,
Port = Configuration.GCM_PORT,
Username = username,
Password = Configuration.GCM_API_KEY,
AutoResolveConnectServer = true,
SocketConnectionType = SocketConnectionType.Direct,
AutoAgents = false,
KeepAlive = true,
AutoRoster = false,
AutoPresence = false,
UseCompression = false,
Show = ShowType.chat
};
xmpp.OnReadSocketData += Xmpp_OnReadSocketData;
xmpp.OnWriteSocketData += Xmpp_OnWriteSocketData;
xmpp.OnLogin += Xmpp_OnLogin;
xmpp.OnMessage += Xmpp_OnMessage;
xmpp.OnError += Xmpp_OnError;
xmpp.OnClose += Xmpp_OnClose;
xmpp.OnAuthError += Xmpp_OnAuthError;
xmpp.Open();
}
这是与 ccs 的交互(从 OnReadSocketData 和 OnWriteSocketData 事件中捕获)
To CCS<<11:59:58 834
<stream:stream to='gcm.googleapis.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>
From CSS>> 11:59:59 037
<stream:stream from="gcm.googleapis.com" id="AF8BBDE576QWEFF3543" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">
From CSS>> 11:59:59 101
<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>
To CCS<<11:59:59 115
<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">ADIwNjAxOTEwOTA2Mlw0MGjkdf4y67fvbjjdgESnhaa2tFX3hIcm56NXhWZndJclpFUmlMbnBqNVFIdkk=</auth>
From CSS>> 11:59:59 312
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>ism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features>
From CSS>> 11:59:59 314
</stream:stream>urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>ism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features>