【问题标题】:How Can I push Notification from my android app using by Nodejs如何使用 Nodejs 从我的 android 应用程序推送通知
【发布时间】:2017-03-02 06:00:12
【问题描述】:

我正在开发一个 android 应用程序,它几乎完成了,只是我想从我的应用程序推送通知,使用 nodejs 和 ONE Signal 服务,我从我的应用程序后端使用 nodejs 和 mongodb。我连接了一个信号和android studio我有服务器api密钥,项目号和应用程序id,但我不知道如何在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);
        });
    });

【问题讨论】:

    标签: android node.js notifications push onesignal


    【解决方案1】:

    /* 需要 express, body-parser,express,fcm-push...其他模块 */
    试试这个功能 ->

    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);
            }
        });
    }
    

    【讨论】:

    • 感谢您的回复,但我有更多简单的问题,我是否需要为该代码创建架构,例如 notificationschema ?
    猜你喜欢
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-17
    • 2019-06-10
    相关资源
    最近更新 更多