我正在从Firebase发送推送通知,但是如果我在设备接收邮递员通知时使用相同的参数,但在其余api上使用相同的参数,则表示成功但未收到通知。
if (SendTo.Length > 0)
{
FCMBody body = new FCMBody();
FCMNotification notification = new FCMNotification();
notification.title = Title;
notification.body = Body;
FCMData data = new FCMData();
data.key1 = ((int)ToPage).ToString();
data.key2 = ToParam;
data.key3 = ToParam2;
data.key4 = ToParam3;
body.registration_ids = SendTo;
body.notification = notification;
body.data = data;
return SendNotification(body).Result;
}
return false;
static async Task<bool> SendNotification(FCMBody fcmBody)
{
var httpContent = JsonConvert.SerializeObject(fcmBody);
var client = new HttpClient();
var authorization = string.Format("key={0}", "My firebase key");
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", authorization);
var stringContent = new StringContent(httpContent);
stringContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
string uri = "https://fcm.googleapis.com/fcm/send";
var response = await client.PostAsync(uri, stringContent).ConfigureAwait(false);
var result = response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
return true;
else
return false;
}
我复制了api的主体部分,并且所有参数都是相同的,并由邮递员发送并由设备接收。