【发布时间】:2018-07-12 15:41:56
【问题描述】:
我正在使用 fcm 节点模块发送推送通知。试图发送到一个组(具有一个设备令牌的组)。并且它为单个警报提供相同推送的重复副本(每次 4 个副本)。它应该只交付一个。我用过fcm-node(版本:1.2.1)、fcm-push(版本:1.1.3)等。
nodejs代码如下:
Alerts.pushTry = function (cb) {
var serverKey = "abcd"; //put your server key here
var deviceToken = 'group_key'; // required
var FCM = require('fcm-node');
var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
to: deviceToken,
notification: {
title: 'Group 555 test'+ ((new Date()).getTime()),
body: 'Body of your push notification'
},
data: {
my_key: 'my value',
my_another_key: 'my another value'
}
};
fcm.send(message, function(err, response) {
console.log("sent");
if (err) {
console.log(err);
console.log("Something has gone wrong!");
cb(err);
} else {
console.log("Successfully sent with response: ", response);
cb(null, response);
}
});
};
谁能帮帮我?
【问题讨论】:
-
我也遇到了这个问题,你找到解决办法了吗?
-
是的,我已经使用了请求模块并直接连接了 fcm 推送通知 url,而不依赖于这些类型的 npm 模块有未解决的问题。
-
你能告诉我你是怎么做的吗?即代码
-
var request = require('request');
-
request({ url: 'fcm.googleapis.com/fcm/send';, method: "POST", headers: { "content-type" : "application/json", "Authorization" : key=${constants.FCM_SERVER_KEY}, "project_id": constants.FCM_SENDER_ID, }, json: message }, function(error, response, body) {});
标签: node.js firebase push-notification firebase-cloud-messaging