用C#寫了一段後台利用FCM推播的code
回傳的訊息
{"message_id":7638543291219000886}
只有收到這個回應,但是我的手機並沒有收到推播
try
{
//伺服器
string applicationID = "AIzaSyBhYzPkQgYND6P5cpLvEMoTUbJpgJeks";
string senderId = "968899743755";
string deviceId = "/topics/ios";
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 = "test",
title = "test",
sound = "default"
}
};
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;
}
}
}
}
}
catch (Exception ex)
{
string str = ex.Message;
}
用FCM平台手動推播可以成功
使用以上的CODE有回傳成功的訊息,但手機沒收到
麻煩有經驗的大哥幫我解答了