我正在尝试使用FCM将通知推送到Android设备,但似乎我遗漏了一些东西。这些是我遵循的步骤
我使用了这段代码
var regId = "device id";
string SERVER_API_KEY = "Firebase Server key";
var SENDER_ID = "Sender ID";
var value = "Test Notification";
WebRequest tRequest;
tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key={0}", SERVER_API_KEY));
tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "®istration_id=" + regId + "";
Console.WriteLine(postData);
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
string sResponseFromServer = tReader.ReadToEnd();
tReader.Close();
dataStream.Close();
tResponse.Close();
我总是收到Mismatch Sender Id错误。我错过了任何步骤吗?或者我必须在移动应用上做点什么吗?
答案 0 :(得分:0)
我发现了错误。作为一名后端开发人员,我只从事C#部分工作。从移动应用程序方面还有一个步骤要做。移动应用程序应该允许从发件人ID列表中接收消息,因此必须允许我在移动应用程序端使用我在C#代码中使用的消息。一旦我做到了,它就有效了