[英]Firebase Push Notification using C#
如何使用C#向Firebase中的多个用户发送推送通知。
我使用FCM向一个用户发送通知,但是当我尝试向多个用户发送通知时,我遇到了错误请求异常。
提前致谢 ..
string applicationID = NotificationConstants.GoogleNotificationData.GoogleAppID;
string senderId = NotificationConstants.GoogleNotificationData.SenderId;
WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.ContentType = "application/json";
var data = new
{
to = "f3fMjgIVqog:APA91bHxfhY5zbCmHqkfG2igd499DIYVVbqvi6SUT_ZeiMa9W-abce0f9tEqIupgQHiTcoU2eZKA-dZboteeWsbOsrFWdtjjPBxzI3YJTSvPJSUiSOBicBd7xd1Hb2vtioSUNvMtz0-f",
data = dataObject
};
var json = JsonConvert.SerializeObject(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;
}
}
}
}
您的数据应该像
string [] registration_ids = { deviceRegId };
var data= new
{
// to = deviceRegId, // uncomment to notify single user
registration_ids = registration_ids,
priority = "high",
notification = new { title, body }
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.