postman 通过REST API为Firebase中的用户组发送通知

ppcbkaq5  于 8个月前  发布在  Postman
关注(0)|答案(2)|浏览(129)

我正在尝试发送用户列表的通知,这是否适用于Firebase REST API。我尝试并成功地为特定用户发送通知和广播通知,但我没有找到一组用户的示例请求!
下面是我用于Broadcast by Postman的请求:
网址:

https://fcm.googleapis.com/fcm/send

正文:

{ "data": 
{
 "title": "Firebase notification",
 "detail": "I am firebase notification. you can customise me. enjoy"
 },
 "notification":{
      "title":"Hi from Postman ",
      "body":"great match!"
    },
 "to":"/topics/all"
// I don't think to could accept an array of the users device token 
 }
s4n0splo

s4n0splo1#

Firebase Cloud Message没有用户的概念,也没有用户组的概念。相反,它有两种方法来定位消息:
1.您可以将消息发送到一个或多个FCM令牌,这是每次安装应用时生成的令牌。通过将消息发送到令牌,发送者确定他们将消息发送给谁。
1.您可以向应用示例订阅的主题发送消息。通过向主题发送消息,订阅者可以确定他们接收的消息。
这两个都没有比另一个更好,因为它们都有自己的用例。选择通常是方便与控制之一。

  • 如果您将消息发送到一个主题,则必须假设所有用户都可以接收到该消息(因为他们是订阅主题的用户)。
  • 如果希望完全控制消息的接收者,则应在服务器上保留一个FCM令牌列表,并传递令牌以将消息传递到API调用中。
s2j5cfk0

s2j5cfk02#

Firebase为推送通知提供了Rest API。这是基本URL https://fcm.googleapis.com/fcm/send
如果我们需要一次为多个设备发送通知,那么我们需要在POST请求中传递这个JSON主体。

{
  'data': {
    'title': 'New Message',
    'message': 'You have a new message',
    'key1': 'value1',
    'key2': 'value2'
  },
  'notification': {
    'title': 'Your Notification Title',
    'body': 'Your Notification Message Body',
    'android_channel_id': 'channel_id_for_receive_notification',
    'mutable_content': true,
    'sound': 'Tri-tone'
  },
  'registration_ids': ["token1", "token2", "token3", ...as needed ]  
  
},

在这里,data对象包含可用于自定义消息的自定义键值对。notification对象包含消息的标题和正文。registration_ids数组包含目标受众的设备令牌。

相关问题