我正在使用FCM节点模块发送推送通知。试图发送到一个组(带有一个设备令牌的组(。所有它都会提供相同推动的复制副本(每次4份(以获取单个警报。它应该只交付一个。我已经使用了FCM节点(版本: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) {
//You code
});