【问题标题】:Node js with Firebase (FCM) push notification带有 Firebase (FCM) 推送通知的 Node js
【发布时间】:2018-10-29 11:48:31
【问题描述】:

我正在使用节点 js 开发 REST api,并且有一个用于发送 firebase 推送通知的 REST 端点。我的代码如下,

const bodyParser = require('body-parser');
var cors = require('cors');
var FCM = require('fcm-node');
//var FCM = require('fcm-push');

router.post('/pushmessage', function (req, res) {

    var serverKey = 'server key taken from firebase site cloud messaging tab';
    var fcm = new FCM(serverKey);
    var reqObj = req.body;
    var token = reqObj.userToken;
    console.log("Token Value  :   " + token);
    var message = {
        to: token,
        collapse_key: 'xxxxxxxxxxxxxx',
        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});
            console.log("error : "+err);
        } else {
            console.log("MESSAGE SEND");
            res.json({status: 1, message: response});
        }
    })
});

从 android 客户端应用程序生成的推送 id 正确命中此端点。但总是会出错 {"multicast_id":6340735554735214,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]} 请求被击中后。请问有人可以帮助我吗?这个问题之前在here 中提出过。

但这对我不起作用。我也试过thisthis

但没有任何进展。请帮忙。

【问题讨论】:

  • 如果您可以发布实际引发的错误而不是您记录的消息,这样社区可以帮助您,那就太好了。
  • 谢谢小费。消息错误:{"multicast_id":6340447350554262714,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}
  • @KoshanSamarasinghe 什么是折叠键?你在那里添加了什么?

标签: node.js firebase push-notification


【解决方案1】:

不强制只依赖GCM,现在有很多包可以发送pushNotification

下面列出了两个节点包。

使用 fcm-call,

let FCM = require('fcm-call');
const serverKey = '<Your Server Key>'; 
const referenceKey = '<Your reference key>'; //Device Key
let title = '<Your notification title here.>';
let message = '<Your message here>';

FCM.FCM(serverKey, referenceKey, title, message);

这个小 sn-p 会在 2-3 秒内将 PushNotification 发送到您的专用设备。

快乐通知。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    • 2017-02-05
    相关资源
    最近更新 更多