FCM(Firebase云消息传递)发送到多个设备
我执行此代码以使用FCM库将通知推送到移动设备
public string PushFCMNotification(string deviceId, string message) { string SERVER_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxx"; var SENDER_ID = "xxxxxxxxx"; var value = message; WebRequest tRequest; tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); tRequest.Method = "post"; tRequest.ContentType = "application/json"; tRequest.Headers.Add(string.Format("Authorization: key={0}", SERVER_API_KEY)); tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID)); var data = new { to = deviceId, notification = new { body = "This is the message", title = "This is the title", icon = "myicon" } }; var serializer = new JavaScriptSerializer(); var json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.ContentLength = byteArray.Length; Stream dataStream = tRequest.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); WebResponse tResponse = tRequest.GetResponse(); dataStream = tResponse.GetResponseStream(); StreamReader tReader = new StreamReader(dataStream); String sResponseFromServer = tReader.ReadToEnd(); tReader.Close(); dataStream.Close(); tResponse.Close(); return sResponseFromServer; }
现在,如何向多设备发送消息,假设字符串deviceId参数替换为List devicesIDs。
你能帮我吗
相关分类