有人可以帮助我吗? 这是我的代码:
private void btnSendNotification_Click(object sender, EventArgs e)
{
tbxResponse.Clear();
string response = PushNotification();
tbxResponse.Text = response;
}
private static string PushNotification()
{
string response;
try
{
// From: https://console.firebase.google.com/project/x.y.z/settings/general/android:x.y.z
// Projekt-ID: x.y.z
// Web-API-Key: A...Y (39 chars)
// App-ID: 1:...:android:...
// From https://console.firebase.google.com/project/x.y.z/settings/
// cloudmessaging/android:x,y,z
// Server-Key: AAAA0... ...._4
string serverKey = "AAAAs8qv4ZM:APA91bEED4RRv-u3ALAObLmBlTMRwwRtfMyVDZweB6tCTz4y33sIR_D-p7chnFsVKAXF3Mg2ajmX6_gYPTaBXew0IbRe8GfZHpd0LW0gy415-5DJPQZBmY9BUXAMz6qEdf6bQ_FLQKgZqgv-pyTK7unV4pDattdGag"; // Something very long
string senderId = "772199670163";
string deviceId = "GxzonRZepM:APA91bG3x1EhCU0fpg06T7MyCeFKCs-tY8mb3zKqOWh9docYJXkJkSZ6oq2a6UEorZf9rAwHxsAzu28X0e0coRPX5HJzLQ27atCc_Xh6Xoem2LLWOaC3c76Hl78JSyziIt-9aL4OF88p"; // Also something very long,
// got from android
//string deviceId = "//topics/all"; // Use this to notify all devices,
// but App must be subscribed to
// topic notification
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 = "Greetings",
title = "Augsburg",
sound = "Enabled"
}
};
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(data);
Byte[] byteArray = Encoding.UTF8.GetBytes(json);
tRequest.Headers.Add(string.Format("Authorization: key={0}", serverKey));
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();
response = sResponseFromServer;
}
}
}
}
}
catch (Exception ex)
{
response = ex.Message;
}
return response;
}
但是我在输出中给出了一个错误: {“ multicast_id”:4889294147329191934,“成功”:0,“失败”:1,“ canonical_ids”:0,“结果”:[{“错误”:“ MismatchSenderId”}]}}
这是我的项目信息: 项目名称:Webservice1 面向公众的名称:project-772199670163 项目编号:webservice1-75bea Web API密钥:AIzaSyBgmP0edEurv_tPTo9yTlkVXIFLOC-lMFQ
服务器密钥:AAAAs8qv4ZM:APA91bEED4RRv-u3ALAObLmBlTMRwwRtfMyVDZweB6tCTz4y33sIR_D-p7chnFsVKAXF3Mg2ajmX6_gYPTaBXew0IbRe8GQZDQY4YQBQQ4YQB4KQQB4KQQB4QB4QB2Q6Q4YQ2QQ4YQ4YQ4YQ4YQ2QQ4YQ2Q6Q6A0E0E0E0E0B0B4CQ2BQ4YQ4YQ6Y0E)
旧版服务器密钥:AIzaSyChVKjrcCyO2uU1ryHpzrWfP1lIgkr-vN4 发件人ID:772199670163
我必须做什么?
或通过Web服务或Windows应用程序向移动设备发送推送通知的另一种方式