繁体   English   中英

如何使用.Net为用户细分和主题实现Firebase通知API

[英]How to implement Firebase notification API for user segment and topic using .Net

以下代码我用来发送单个设备的通知及其正常工作。 但我想为特定组的客户端应用程序发送通知。

WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
        tRequest.Method = "post";
        tRequest.ContentType = "application/json";
        var objNotification = new
        {
            to = "Device_Token_Id",
            notification = new
            {
                title = "Notification Title",
                body = "Notification message"

            },

            priority = "high"
        };
        string jsonNotificationFormat = Newtonsoft.Json.JsonConvert.SerializeObject(objNotification);

        Byte[] byteArray = Encoding.UTF8.GetBytes(jsonNotificationFormat);

        tRequest.Headers.Add(string.Format("Authorization: key={0}", "Server_Api_Key"));
        tRequest.Headers.Add(string.Format("Sender: id={0}", "Sender_Id"));
        tRequest.ContentLength = byteArray.Length;
        tRequest.ContentType = "application/json";
        using (Stream dataStream = tRequest.GetRequestStream())
        {
            dataStream.Write(byteArray, 0, byteArray.Length);

            using (WebResponse tResponse = tRequest.GetResponse())
            {
                using (Stream dataStreamResponse = tResponse.GetResponseStream())
                {
                    using (StreamReader tReader = new StreamReader(dataStreamResponse))
                    {
                        String responseFromFirebaseServer = tReader.ReadToEnd();

                        Console.WriteLine(responseFromFirebaseServer);
                        Console.ReadLine();                                                  

                    }
                }

            }
        }

请让我知道是否有人知道如何实现此api,以便向特定用户组或所有人发送通知。

假设您是指用户群在Firebase控制台中可用,那么答案是您无法通过Firebase Cloud Messaging HTTP API定位用户群。 目前,这仅限于Firebase控制台。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM