node.js - 付款重定向成功后,NodeJS Express Session 为空
问题描述
我在我的一个电子商务网站中集成了一种付款方式
现在,当我在付款成功完成后进行付款时,它会重定向到请求中提到的 URL,但是当涉及到我的 URL 时,平台上存储的所有会话都会被清除
这是带有 SQL 会话表的节点中会话的会话配置
let session = require('express-session');
let MySQLStore = require('express-mysql-session')(session);
let db = require('./knexfile.js');
let options = db[environment]['connection'];
let sessionStore = new MySQLStore(options);
app.use(session({
secret: 'ecommerceSiteSecrets',
cookie: {
maxAge: 365 * 24 * 60 * 60 * 1000,
expires: false
},
store: sessionStore,
saveUninitialized: true,
resave: true,
}));
现在在我付款之前我的会话如下
Session {
cookie:
{ path: '/',
_expires: false,
originalMaxAge: false,
httpOnly: true },
flash: {},
customer_id: 2,
email: 'tt1@gmail.com',
name: 'Alex Stuart',
type: 'customer',
user:
{ customer_id: 2,
customer_first_name: 'Alex',
customer_last_name: 'Stuart',
customer_email: 'tt1@gmail.com',
customer_status: 1
},
orderSession:
{ cart_id: '348,',
customer_id: '2',
amount: '225',
pay_method: '1'
}
}
在成功完成支付后,支付网关将我重定向到成功页面,我想在该页面中执行用于捕获支付信息并将其存储在数据库中的代码
Session {
cookie:
{ path: '/',
_expires: false,
originalMaxAge: false,
httpOnly: true
}
}
请指导我我在哪里做错了!
解决方案
尝试使用 node-sessionstorage 方法。您可以在提出付款请求之前设置所需的会话数据,在付款完成后,您需要为您的会话获取会话存储并重新更新您的节点会话。
例如,获取会话并将其保存在会话存储中
customer_id: 2,
email: 'tt1@gmail.com',
name: 'Alex Stuart',
type: 'customer',
user:
{ customer_id: 2,
customer_first_name: 'Alex',
customer_last_name: 'Stuart',
customer_email: 'tt1@gmail.com',
customer_status: 1
},
orderSession:
{ cart_id: '348,',
customer_id: '2',
amount: '225',
pay_method: '1'
}
您可以使用以下方法作为参考 -
const storage = require('node-sessionstorage');
storage.setItem('userSession', 'YourSessionArray');
console.log('item set:', storage.getItem('userSession'));
推荐阅读
- shell - 用名称标记树文件
- widget - ADLS 文件中的 Databricks 作业小部件
- python-3.8 - 如何创建python环境的快捷方式文件?
- docker - 从 Dockerfile CMD 调用 sh 文件时无法在 docker 容器内设置环境变量
- c++ - 在 C++ 中将 HTTPLib::Post 作为非阻塞函数调用?
- python - 从Selenium Python获取标题
- reactjs - 电子反应样板应用程序的国际化?
- python - 如何在Python中对数组数字进行排名
- php - Symfony 无法访问自定义类/方法中的 EntityManager
- react-native - _NativeStripeSdk.default.createToken 未定义