如何在Node服务器上处理FCM上游消息



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

您是否使用FCM -node包获取FCM令牌?使用它,我们可以注册设备看看我的完整代码我用它向移动设备发送通知

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

最新更新