在MySQL DB中存储通知详细信息(使用FCM推送通知)

发布于 2025-02-04 05:04:58 字数 996 浏览 4 评论 0原文

我正在node.js和express中编写服务器。 我正在通过Firebase通知发送给我的应用程序用户通知,然后将其发送给用户,我想在MySQL DB 中存储我的通知详细信息。

我在存储通知详细信息时有一个问题,它不起作用(行不确定,并且在db表中没有数据添加数据)。

这是我的相关代码:

 const message_notification = {
    notification: {
        title: "notification_title",
        body: "notification_body"
    }
};

const notification_options = {
    priority: "high",
    timeToLive: 60 * 60 * 24
};


admin.messaging().sendToDevice(device_token, message_notification, notification_options)
    .then( response => {      
       
        //doesn't work
        mySqlConnection.query(`insert into notifications (notification_id, body, title) values
        (?,?,?)`, [response.multicastId, message_notification.notification.body, message_notification.notification.title], (err,rows)=>
        {
            try
            {
                console.log(rows);
            }

            catch(err)
            {
                console.log(err)
            }
        });
        })

I'm writing a server in Node.js and express.
I'm sending to my app users push notifications via firebase notifications, and after I send it to the user, I want to store my notification details in MySql DB.

I have a problem in storing the notification details, it doesn't work (rows is undefined and no data is added to the DB table).

This is my relevant code:

 const message_notification = {
    notification: {
        title: "notification_title",
        body: "notification_body"
    }
};

const notification_options = {
    priority: "high",
    timeToLive: 60 * 60 * 24
};


admin.messaging().sendToDevice(device_token, message_notification, notification_options)
    .then( response => {      
       
        //doesn't work
        mySqlConnection.query(`insert into notifications (notification_id, body, title) values
        (?,?,?)`, [response.multicastId, message_notification.notification.body, message_notification.notification.title], (err,rows)=>
        {
            try
            {
                console.log(rows);
            }

            catch(err)
            {
                console.log(err)
            }
        });
        })

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文