2017-03-02 46 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的代码创建模式? –