我尝试向单个设备发送消息,即单个注册ID,它可以正常工作。但是,当我尝试添加多个注册ID时,会出现“InvalidServerResponse”错误。 例如:对于regTokens ='regId1'可以运行; 但是对于regTokens = ['regId1','regId2']无法运行。
var FCM = require('fcm-node');
// Add API Key
var fcm = new FCM('<server-key>');
exports.sendMessage = function (regTokens, messageToSend, callback) {
var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
to: regTokens,
data: {
ar_message: messageToSend
}
};
fcm.send(message, function(err, response){
if (err) {
console.log("Something has gone wrong!",err);
} else {
console.log("Successfully sent with response: ", response);
}
callback(err, 'Success');
});
}
regTokens
是什么,这很可能是它失败的关键原因。 - Frank van Puffelen