FCM(Firebase云消息传递)推送通知与Asp.Net

FCM

我已经在下面的方法中使用asp .netGCM消息推送到谷歌服务器,

GCM推送通知与Asp.Net

现在我已经计划升级到FCM方法,任何人都有这个想法或在asp .net开发这个让我知道..

Solutions Collecting From Web of "FCM(Firebase云消息传递)推送通知与Asp.Net"

用于Firebase 云消息传递的 C# 服务器端代码

 using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Web; using System.Web.Script.Serialization; namespace Sch_WCFApplication { public class PushNotification { public PushNotification(Plobj obj) { try { var applicationID = "AIza---------4GcVJj4dI"; var senderId = "57-------55"; string deviceId = "euxqdp------ioIdL87abVL"; WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; var data = new { to = deviceId, notification = new { body = obj.Message, title = obj.TagMsg, icon = "myicon" } }; var serializer = new JavaScriptSerializer(); var json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID)); tRequest.Headers.Add(string.Format("Sender: id={0}", senderId)); tRequest.ContentLength = byteArray.Length; using (Stream dataStream = tRequest.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); using (WebResponse tResponse = tRequest.GetResponse()) { using (Stream dataStreamResponse = tResponse.GetResponseStream()) { using (StreamReader tReader = new StreamReader(dataStreamResponse)) { String sResponseFromServer = tReader.ReadToEnd(); string str = sResponseFromServer; } } } } } catch (Exception ex) { string str = ex.Message; } } } } 

APIKey和senderId,你会在这里———如下图(下图)(去你的firebase应用程序)

步。 1

步。 2

步。 3

我不相信你发送推送通知的方式有任何改变。 在FCM中,您也将像使用GCM一样进行HTTP POST请求:

 https://fcm.googleapis.com/fcm/send Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA { "data": { "score": "5x1", "time": "15:10" }, "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..." } 

阅读有关FCM服务器的更多信息。

我现在看到的唯一变化就是目标url。 期。

这是我喜欢vb的VbScript示例:

 //Create Json body posturl="https://fcm.googleapis.com/fcm/send" body=body & "{ ""notification"": {" body=body & """title"": ""Your Title""," body=body & """text"": ""Your Text""," body=body & "}," body=body & """to"" : ""target Token""}" //Set Headers :Content Type and server key set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP") xmlhttp.Open "POST",posturl,false xmlhttp.setRequestHeader "Content-Type", "application/json" xmlhttp.setRequestHeader "Authorization", "Your Server key" xmlhttp.send body result= xmlhttp.responseText //response.write result to check Firebase response Set xmlhttp = nothing