android - 如何在 Node 服务器中处理 FCM 上游消息?

标签 android node.js xmpp firebase-cloud-messaging

我正在使用 node-xcs 模块在 NodeJs 中创建 XMPP CCS 服务器,但是在该模块中没有发送 ACK 消息的方法,需要发送回 FCM。

最佳答案

您是否使用 fcm-node 包来获取 FCM token 。使用它我们可以注册设备看看我的完整编码我用它向手机发送通知

var FCM = require('fcm-node');
exports.SendNotification = function(msg,title,type,id,user_id,api_token)
{

                        var fcm = new FCM(constants.serverKey);

                            var message = {
                                        registration_ids :  api_token,
                                      notification: {
                                        title: title,
                                        body:msg
                                        },
                                    data: {
                                        type: type,
                                                id:id,
                                                user_id:user_id
                                    }
                                };

                                fcm.send(message, function(err, response){
                                    if (err)
                                        {
                                        console.log("Error for Send Notification",err);
                                                return;
                                    }
                                        else
                                        {
                                        console.log("Successfully sent Notification", response);
                                                return;
                                        }
                                    });
}

然后像这样调用这个函数

msg='new notification for you'
title='Hello'
id='34'
user_id='34'
result='api_token'//save this token in database and retrive using user_id
SendNotification(msg,title,'START_APPOINTMENT',id,user_id,result);

关于android - 如何在 Node 服务器中处理 FCM 上游消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39189237/

相关文章:

javascript - 在 ReactJS 中,如何通过将 props 从父组件传递到子组件来初始化状态?

javascript - 如何检索 javascript 文件中的所有函数名称

android - Executor 的 Runnable 中的变量

android - 验证 EditText 是否为空并等待用户输入数据

Android shift 键监听器

javascript - 如何在日期对象上设置 LocaleHours()?

ios - 如何检测用户正在输入消息?

c++ - 使用 Gloox C/C++ 的 XMPP 握手流程

ios - 如何在iOS中通过xmpp删除单个聊天?

java - 捕获的图像总是显示横向并且无法解决setRotate