我陷入了一个cordova android应用程序的问题,我试图通过cordova的firebase插件接收fcm通知,每次我通过firebase控制台发送通知时,设备都会接收到该消息,但是当我试图在我的服务器端使用firebase api时,它会说它发送了通知(状态200)。但设备没有收到任何通知。
即使当我尝试测试邮递员发送通知时,也会出现同样的情况,发送状态200出现,但设备上没有消息到达。
我的服务器端是在.net上构建的。请,如果有人能帮我,我将不胜感激。

Public Function SendNotificationToFirebaseCloud() As [String]
    Dim result = "-1"
    Dim webAddr = "https://fcm.googleapis.com/fcm/send"

    Dim httpWebRequest = DirectCast(WebRequest.Create(webAddr), HttpWebRequest)
    httpWebRequest.ContentType = "application/json"
    httpWebRequest.Headers.Add("Authorization:key=MY_AUTHORIZATION_KEY")
    httpWebRequest.Method = "POST"

    Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream())
        Dim json As String = "{""to"" : ""MY_FIREBASE_TOKEN"", ""priority"": ""high"", ""data"" : { ""name"" : ""VIP"", ""othername"" : ""Leiloes"" }}"
        streamWriter.Write(json)
        streamWriter.Flush()
    End Using

    Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
    Using streamReader = New StreamReader(httpResponse.GetResponseStream())
        result = streamReader.ReadToEnd()
    End Using

    Return result
End Function

最佳答案

json中应该有一个“notification”字段,因为结构需要:

{
    "to" : "xxxx",
    "priority" : "high",
    "notification" : {
        "title" : "Your title",
        "body" : "Your body",
        "click_action" : "FCM_PLUGIN_ACTIVITY", //(This one is important as it's used to trigger the event when you click on the notification)
        "icon" : "myicon",
        "sound" : "default"
    },
    "data" : {
        "name" : "VIP",
        "othername" : "Leiloes"
    }
}

09-04 22:35
查看更多