我想在單個fcm請求中向多個設備發送通知。 我的通知文本是相同的所有devices.i必須發送更多然後10000通知在同一時間所有用戶和文本是相同的,所以我想在最低fcm請求發送所有通知。 我正在使用c#asmx服務。 聽到是我的代碼。如何將fcm通知發送到單個fcm請求中的多個設備請求
string regid =「fcm_reg_id1,fcm_reg_id2」像這樣。
string applicationID =「abcd」;
string SENDER_ID =「123456」;
string regid="c_Z5yRoj4TY:APA91bGry2g_CIA1xaRy_LscxOvFX6YHqasKA96TjpG6yi1yytNyM5rtGL6DgxjGMSE5c74d7VdSL6W8zxO1ixVMlpVMwdgcrsGUWV0VfdbddC2XD","c_Z5yRoj4TY:APA91bGry2g_CIA1xaRy_LscxOvFX6YHqasKA96TjpG6yi1yytNyM5rtGL6DgxjGMSE5c74d7";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://fcm.googleapis.com/fcm/send");
httpWebRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
httpWebRequest.Method = "POST";
String collaps_key = "Score_update";
string json = "collapse_key=abcd" + "&data.header=cricket®istration_id=" + regId + "&data.notificationId=" + notificationId + "&data.message=" + msg;
httpWebRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
httpWebRequest.Headers.Add(string.Format("Sender: key={0}", SENDER_ID));
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
//Console.WriteLine(json);
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
using (HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
Console.WriteLine(result);
retmsgid = result.ToString();
if (retmsgid.Trim() != "")
{
ResponceString = result.ToString();
string[] msgsplits = retmsgid.Split(',');
string[] msg1 = msgsplits[0].ToString().Split(':');
ReturnMessageId = msg1[1].ToString();
}
else
{
ReturnMessageId = "0";
}
}
httpResponse.Close();
httpResponse.Dispose();
httpWebRequest = null;
}
}
您可以使用IMEI號碼(需要在您的後端註冊IMEI號碼)從網上執行此操作。因此,您需要使用移動設備上的網絡服務發佈消息。現在,您可以使用IMEI號碼註冊的設備從網絡上廣播您的消息。 –
我想在上面的代碼中的單個請求發送多個通知,我想添加多個註冊ID併發送它。 – user3599175