我正在编写 ac# 服务,它将允许我使用 FCM 发送推送通知。现在,一切正常,但我想使用 FCM 发送批量推送通知。
我希望能够一次向多个设备发送相同的消息。当前取一个注册令牌,然后经过整个过程,然后转到下一个。但是,如果我必须一次向多个号码发送推送通知,这将毫无用处。我最好的选择应该是什么?
代码
public String SendPushNotification(string regtoken)
{
try
{
string applicationID = "#############3";
string senderId = "##########";
string deviceId = regtoken;
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 = message,
title = "",
sound = ""
}
};
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)); …Run Code Online (Sandbox Code Playgroud)