有人可以帮助我使用C#使用XMPP库连接FCM(Firebase云消息传递)服务器吗?
我想使用XMPP发送推送通知。
我正在尝试使用Sharp.Xmpp连接它,如下所示,
public class XmppConnector
{
public XmppConnector()
{
string hostname = "fcm-xmpp.googleapis.com";
string username = "exmple@gcm.googleapis.com";
string password = "example";
using (XmppClient client = new XmppClient(hostname, username, password))
{
try
{
// Setup any event handlers before connecting.
client.Message += OnNewMessage;
// Connect and authenticate with the server.
client.Connect();
}
catch (Exception e)
{
throw e;
}
}
}
/// <summary>
/// Invoked whenever a new chat-message has been received.
/// </summary>
private void OnNewMessage(object sender, Sharp.Xmpp.Im.MessageEventArgs e)
{
Console.WriteLine("Message from <" + e.Jid + ">: " + e.Message.Body);
//throw new NotImplementedException();
}
}
但它不起作用,我甚至试过另一个端口(5235和5236)。如果您有任何示例,请分享。
提前致谢。
答案 0 :(得分:0)
我正在使用https://github.com/ForNeVeR/Jabber-Net
myJabberClient = new JabberClient();
myJabberClient.User = Globales.FIRABASE_MESSAGING_USER + "@gcm.googleapis.com";
myJabberClient.Password = Globales.FIREBASE_MESSAGING_KEY;
myJabberClient.Server = Globales.FIRABASE_GCM_XMPP_SERVER;
myJabberClient.Resource = "MyTestClient";
myJabberClient.Port = 5235;
myJabberClient.AutoReconnect = 1;
myJabberClient.AutoPresence = false;
myJabberClient.AutoRoster = false;
myJabberClient.KeepAlive = 10;
myJabberClient.PlaintextAuth = true;
myJabberClient.AutoLogin = true;
myJabberClient.AutoStartTLS = false;
myJabberClient.SSL = true;
myJabberClient.OnMessage += async (s, msg) => {
// Do stuff here
}
myJabberClient.Connect();
我使用HTTP API推送通知。 我只是在向CCS服务器发送上游接收消息的ACK消息时遇到问题,因为&#34;:&#34;某些注册ID中的字符
答案 1 :(得分:0)