我想在单个fcm请求中向多个设备发送通知.
我的通知文本对于所有设备都是相同的.我必须同时向所有用户发送超过10000个通知,并且文本是相同的,所以我想以最小fcm请求发送所有通知.
我正在使用c#asmx服务.
听到的是我的代码.
我的通知文本对于所有设备都是相同的.我必须同时向所有用户发送超过10000个通知,并且文本是相同的,所以我想以最小fcm请求发送所有通知.
我正在使用c#asmx服务.
听到的是我的代码.
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; } }
解决方法
自
FCM does not allow发送消息时指定超过1000个注册ID:
This parameter specifies a list of devices (registration tokens,or
IDs) receiving a multicast message. It must contain at least 1 and at
most 1000 registration tokens.
您只有选项是向topic发送消息