FCM一次发送到两个键?

时间:2018-04-13 18:35:41

标签: android firebase firebase-cloud-messaging

FCM是否有办法一次性发送到两个服务器密钥?我目前正在使用以下代码发送通知

const rp = require("request-promise");

const rawKeys = "key-one, key-two";

function sendToKey(serverKey) {
  const requestOptions = {
    method: "POST",
    uri: "https://fcm.googleapis.com/fcm/send",
    headers: {
      Authorization: "key=" + serverKey
    },
    json: true,
    body: {
      to: "Device Token Here",
      priority: "high",
      content_available: true,
      notification: {
        title: "Test Title",
        body: "Test Body",
        deepLink: "https://google.com",
        sound: "default"
      },
      data: {
        title: "Test Title",
        body: "Test Body",
        deepLink: "https://google.com"
      }
    }
  };

  return rp(requestOptions)
    .then(resp => {
      console.log(JSON.stringify(resp));
    });
}

rawKeys.split(",").map(serverKey => sendToKey(serverKey));

我正在尝试避免运行多个请求,因此有一种方法可以在一个请求中发送到两个密钥吗?

0 个答案:

没有答案