Fcm通知push android/IOS nodejs

问题描述:

我正在寻找从Nodejs服务器发送通知,但我收到了一些我不知道如何解决它的错误。有人能帮助我吗?我发现这个可能的解决方案在互联网上 - >URLFcm通知push android/IOS nodejs

这是我的NodeJS

var FCM = require('fcm-push'); 

function sendNotification(){ 

var serverKey = 'AAAAJnK3Ing:AP-(more caracters)AwAlBL_CvXIkFM2UufYZHYkvhC7FP3Tu16mlI'; 
var fcm = new FCM(serverKey); 

var message = { 
    to: 'd2b2v(more caracters token)DUmAXqU-uHptJJLRPXukl', 
    /*data: { 
     your_custom_data_key: 'your_custom_data_value' 
    },*/ 
    notification: { 
     title: 'notification', 
     body: 'This is a notification from node' 
    } 
}; 

//callback style 
fcm.send(message, function(err, response){ 
    if (err) { 
     console.log("****************************************************") 
     console.log(message) 
     console.log("Something has gone wrong!"); 
    } else { 
     console.log("Successfully sent with response: ", response); 
    } 
}); 

//promise style 
fcm.send(message) 
    .then(function(response){ 
     console.log("Successfully sent with response: ", response); 
    }) 
    .catch(function(err){ 
     console.log("----------------------------------------------------") 
     console.log("Something has gone wrong!"); 
     console.error(err); 
    }) 

} 

module.exports = { 
    sendNotification 
} 

I am getting this error

try代码检查,如果你的防火墙允许对443端口连接。它似乎不能创建连接。

+0

是的,它是开放和倾​​听 –