FCM(Firebase云消息传递)推送通知与Asp.Net [英] FCM (Firebase Cloud Messaging) Push Notification with Asp.Net
本文介绍了FCM(Firebase云消息传递)推送通知与Asp.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我已经计划升级到 FCM
方法,任何人都有这个想法或在 asp.net中
让我知道..
解决方案
C#服务器端代码对于Firebase 云消息传递
$ b using System;
using System.Collections.Generic;
使用System.IO;
使用System.Linq;
使用System.Net;
使用System.Text;
使用System.Web;
使用System.Web.Script.Serialization;
$ b命名空间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;
$ b使用(Stream dataStream = tRequest.GetRequestStream())
{
dataStream.Write(byteArray,0,byteArray.Length);
$ b $使用(WebResponse tResponse = tRequest.GetResponse())
{
using(Stream dataStreamResponse = tResponse.GetResponseStream())$ b $使用(StreamReader tReader = new StreamReader(dataStreamResponse))
{
$ String $ s $
string str = sResponseFromServer;
catch(Exception ex)
{
string str = ex.Message;
$ b $ / code>
APIKey和senderId,你在这里得到---------如下图(下图)
(去你的firebase应用程序)
I have already push the GCM
message to google server using asp .net
in following method,
GCM Push Notification with Asp.Net
Now i have planned upgrade to FCM
method, anyone have idea about this or developing this in asp .net
let me know..
解决方案
C# Server Side Code For Firebase Cloud Messaging
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 and senderId , You get is here---------as follow(Below Images) (go to your firebase App)
这篇关于FCM(Firebase云消息传递)推送通知与Asp.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文