2017-02-14 120 views
0

我正在尋找從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

回答

0

try代碼檢查,如果你的防火牆允許對443端口連接。它似乎不能創建連接。

+0

是的,它是開放和傾​​聽 –