通过Gloox XMPP库向Google Firebase发送PUSH通知

时间:2017-08-04 14:50:17

标签: firebase push-notification xmpp firebase-cloud-messaging gloox

我尝试将PUSH通知发送到Android设备作为指南(https://firebase.google.com/docs/cloud-messaging/server#connecting),我正在使用Gloox库发送它,但是服务器会回复我一些不可读的数据(\ x15 \ x3 \ x1)来自谷歌服务器并且无法解析:

log: level: 0, area: 8, This is gloox 1.0.20, connecting to fcm-xmpp.googleapis.com:5236...
log: level: 0, area: 32, Connecting to fcm-xmpp.googleapis.com (64.233.188.188:5236)
log: level: 0, area: 32, Connected to fcm-xmpp.googleapis.com (64.233.188.188:5236)
log: level: 0, area: 262144, <stream:stream to="gcm.googleapis.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
log: level: 2, area: 8, parse error (at pos 0): 

1 个答案:

答案 0 :(得分:0)

我解决了,因为Firebase不支持“STARTTLS”,但GLOOX默认启用了“STARTTLS”(在TLS握手之前发送XML)。

我们应该使用以下代码来禁用“STARTTLS”:

    JID jid("8566240108@gcm.googleapis.com");
    j = new Client(jid, "AAAAADMKj3w:APA9178fdsksW-0rDT0dTu1rMoO0N30J_KldYx9XsQ86fd3540bTIR9e54wDLpU0TWdPf8DnsBRZH-YEc5rtHuRMJRPE_92bcKkLNT42JQ-9fzLJW1yu34r89diWiBS6Rt6_56WzUUmJarc2WCDzz2Tj");    
    j->setServer("fcm-xmpp.googleapis.com");
    j->setConnectionImpl(new ConnectionTLS(j, new ConnectionTCPClient(j->logInstance(), "fcm-xmpp.googleapis.com", 5236), j->logInstance()));
    j->setPort( 5236 ); // For release will be 5235  // The TLS and SASL default is enabled
    j->setTls( TLSOptional );
    j->setSasl(true);
    j->registerConnectionListener(this);
    j->registerMessageSessionHandler(this, 0);
    j->disco()->setVersion("PortSIP PBX", "9.0");
    j->disco()->setIdentity("PushSender", "Sender");
    j->disco()->addFeature(XMLNS_CHAT_STATES);