在node.js应用程序中接收GCM推送通知 [英] Receive GCM push notification in node.js app

查看:180
本文介绍了在node.js应用程序中接收GCM推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在node.js中构建了一个命令行应用程序,并希望收到GCM推送通知(命令行应用程序将与iOS / Android应用程序使用的同一组服务进行交互,因此希望使用鉴于GCM可以在iOS上使用(因此不是Android特有的),我希望它可以从node.js中使用为我已经看到很多关于发送来自node.js的推送通知的文章,但一直没有找到有关使用我想如果你不得不发送推送通知给ios和andriod,那么fcm是更好然后gcm使用这个

  router.post('/ pushmessage',function(req,res){
var serverKey =''; //将服务器密钥放在这里
var fcm = new FCM(serverKey);
var token =; //把令牌放在这里你必须发送推送通知的用户
var message = {
to:token,
collapse_key:'your_collapse_key',
notification:{title:'hello',body:'test'},
data:{my_key :'my value',内容:abcv /}
};
fcm.send(message,function(err,response){
if(err){
res.json({status:0,message:err});
} else {
res.json({status:1,message:response});
}
});
});


I'm building a command-line application in node.js and would like to receive GCM push notifications (the command-line app will be interacting with the same set of services that iOS/Android apps use, hence wanted to use the same notification service).

Given that GCM can be used on iOS (and thus is not Android-specific) I am hoping it can be used from node.js as well.

I've seen many articles about sending push notifications from node.js, but haven't been able to find anything about using node.js on the receiving end.

解决方案

i think if you have to send push notification ,to ios and andriod then fcm is better then gcm use this

router.post('/pushmessage', function (req, res) {
    var serverKey = '';//put server key here
    var fcm = new FCM(serverKey);
    var token = "";// put token here which user you have to send push notification
    var message = {
        to: token,
        collapse_key: 'your_collapse_key',
        notification: {title: 'hello', body: 'test'},
        data: {my_key: 'my value', contents: "abcv/"}
    };
    fcm.send(message, function (err, response) {
        if (err) {
            res.json({status: 0, message: err});
        } else {
            res.json({status: 1, message: response});
        }
    });
});

这篇关于在node.js应用程序中接收GCM推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆