使用Azure服务器向主题发送FCM消息不起作用

时间:2017-05-30 09:27:17

标签: azure firebase xamarin.android firebase-cloud-messaging

我正在尝试使用azure服务器向我的C#代码发送消息到Android应用程序,但它不起作用,不确定azure阻止发送消息。这是我的代码片段:

public static void SendNoticeToFcmServer(string id, string title, string apiUrl,string key)
        {
            var jFcmData = new JObject();
            var jData = new JObject();

            jData.Add("body", title);
            jData.Add("sound", "default");
            jFcmData.Add("to", "/topics/" + id);
            jFcmData.Add("priority", "high");
            jFcmData.Add("notification", jData);

            var url = new Uri(apiUrl);

            using (var client = new HttpClient(new NativeMessageHandler()))
            {
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.TryAddWithoutValidation(
                    "Authorization", "key=" + key);

                Task.WaitAll(client.PostAsync(url,
                    new StringContent(jFcmData.ToString(), Encoding.UTF8, "application/json"))
                        .ContinueWith(response =>
                        {

                        }));
            }

        }

0 个答案:

没有答案