2017-03-02 47 views
-1

餘米開發Android應用程序,它幾乎完成了從我的Android應用的推送通知,只是我想推送通知通過的NodeJS使用我的應用程序有一個信號服務,我用從後端的NodeJS和MongoDB我的應用程序我連接了一個信號和Android工作室彼此我有服務器API密鑰,項目編號和應用程序ID,但我不知道如何在nodejs中使用你可以幫助我thnks所有人。我如何使用的NodeJS

嘗試這裏有些東西與代碼的NodeJS:

var GCM = require('node-gcm-ccs'); 
var gcm = GCM('771515397729', 'bff09b26-ecde-446d-a8ff-0b83f23edeab'); 

app.post('/sendnotification',function(req,res){ 

     var message = req.body.message; 
     var registrationId = req.body.registrationId; 

     sendFunction.sendMessage(message,registrationId,function(result){ 

      res.json(result); 
     }); 
    }); 

回答

-1

/*需要表達,身體的解析器,表達,FCM-推...其他模塊*/
試試這個功能 - >

function sendNotification(tokenToSend, menssage) { 
    var serverKey = 'APYKEY'; 
    var fcm = new FCM(serverKey); 

    var message = { 
     to: tokenToSend, // required 
     collapse_key: '', 
     data: {}, 
     notification: { 
      title: 'Push Notification Server', 
      body: menssage, 
      icon: "ic_launcher", 
      sound: "default", 
      color: "#00BCD4" 
     } 
    }; 

    fcm.send(message, function(err, response){ 
     if (err) { 
      console.log("Something has gone in your message wrong!"); 
     } else { 
      console.log("Successfully sent with response: ", response); 
     } 
    }); 
} 
+0

thnk您的答覆,但IHAVE簡單的問題更多,我需要像notificationschema的代碼創建模式? –