我应该使用什么URL?

时间:2016-05-30 20:25:10

标签: android push-notification firebase firebase-cloud-messaging firebase-notifications

我前段时间写了一个应用程序,现在我需要使用推送通知。我使用Firebase来接收通知;到目前为止,非常好。

现在,我需要我的应用程序的管理版本才能创建这些通知,而不是通过控制台发送它们。 This documentation说我应该创建一个POST请求,但它没有解释我要发布到哪个URL。

要使用的网址是什么?

2 个答案:

答案 0 :(得分:1)

看看:

Sending downstream messages

POST REQUEST:

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}

to是设备密钥。 Autorization标头是您的FCM密钥。

答案 1 :(得分:1)

要像firebase控制台一样发送通知,请像这样发出POST请求

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA  

{
   "to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
   "notification" : {
       "body" : "great match!",
       "title" : "Portugal vs. Denmark",
       "icon" : "myicon"
    }
 }

将“通知”用作关键字

非常重要

请参阅:https://firebase.google.com/docs/cloud-messaging/concept-options