发送通知时始终出现来自ASP.net C#的MismatchSenderId错误

时间:2016-10-10 11:36:08

标签: c# asp.net firebase firebase-cloud-messaging appserver

我从云消息标签中获取了applicationIDsenderId。但我总是得到:

{"multicast_id":4754956504020103312,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}

我不确定我做错了什么。

var applicationID = "AIzaS-----------tkDFiyeLE";
var senderId = "59-------7";
string deviceId = TodeviceId;
WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");

tRequest.Method = "post";

tRequest.ContentType = "application/json";

var data = new
{
    to = deviceId,
    notification = new
    {
        body = message,
        title = "Pet Pals",
        icon = "myicon"
    }
};

var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(data);
Byte[] byteArray = Encoding.UTF8.GetBytes(json);

tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
tRequest.Headers.Add(string.Format("Sender: id={0}", senderId));
tRequest.ContentLength = byteArray.Length;

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 sResponseFromServer = tReader.ReadToEnd();
                string str = sResponseFromServer;
            }
        }
    }
}

0 个答案:

没有答案