gpt4 book ai didi

android - 如何在单个 fcm 请求中向多个设备发送 fcm 通知

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:49:18 29 4
gpt4 key购买 nike

我想在单个 fcm 请求中向多个设备发送通知。我的通知文本对于所有设备都是相同的。我必须同时向所有用户发送超过 10000 条通知,并且文本是相同的,所以我想以最小的 fcm 请求发送所有通知。我正在使用 c# asmx 服务。听到是我的代码。

像这样的字符串 regid="fcm_reg_id1,fcm_reg_id2"。

string applicationID = "abcd";

字符串 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&registration_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 发送消息

关于android - 如何在单个 fcm 请求中向多个设备发送 fcm 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41932264/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com