Fcm Notifications推送android / IOS nodejs

时间:2017-02-14 11:39:19

标签: android ios node.js firebase firebase-cloud-messaging

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

这是我在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

1 个答案:

答案 0 :(得分:0)

尝试检查防火墙是否允许在443端口上连接。它似乎无法创建连接。