You need to sign in or sign up before continuing.
Commit c3f88e03 authored by 李超鹏's avatar 李超鹏

修复sessionKey过期问题

parent 4bf622b3
......@@ -230,6 +230,13 @@ export default {
},
async getPaymentInfo(item) {
console.log('-------getPaymentInfo--------', item)
// #ifdef MP-WEIXIN
// 微信小程序 iOS 虚拟支付:后端 paySig 用请求体里的 payerSession(session_key) 现签,
// 下单前必须先校验 sessionKey,失效则自动重登刷新后再下单,避免签名错配。
if (this.isIOSWX) {
return this.virtualPayWithSessionCheck();
}
// #endif
uni.showLoading({
title: '正在获取订单信息'
});
......@@ -245,16 +252,62 @@ export default {
try {
let { data } = await getOrderInfo(params);
console.log('-------getOrderInfos-------', data)
if (this.isIOSWX) {
this.requestVirtualPayment(data,)
} else {
this.startPay(data, item.provider);
}
this.startPay(data, item.provider);
} catch (e) {
this.showToast('获取订单信息失败');
//TODO handle the exception
}
},
// 微信小程序 iOS 虚拟支付专用:下单前校验 sessionKey,失效自动重登后再下单
virtualPayWithSessionCheck() {
console.log('[pay] checkSession 前 session:', uni.getStorageSync(SESSION));
uni.checkSession({
success: () => {
console.log('[pay] checkSession 有效');
this.createVirtualOrder();
},
fail: () => {
// 注意:直接 dispatch Auto_login action,不能用 App.vue 的 autoLogin() 包装——
// 那个有 `if (platform != '1' || checkToken()) return` 守卫,已登录时会直接 return 不刷新
console.log('[pay] checkSession 失效,Auto_login 重登');
uni.showLoading({ title: '登录刷新中', mask: true });
this.$store
.dispatch('Auto_login')
.then(() => {
uni.hideLoading();
console.log('[pay] 重登完成,重新下单');
this.createVirtualOrder();
})
.catch(err => {
uni.hideLoading();
console.log('[pay] 重登失败', err);
this.showToast('登录已过期,请重新登录');
});
}
});
},
async createVirtualOrder() {
uni.showLoading({ title: '正在获取订单信息' });
// 重登刷新的是 storage;组件 data 的 session 是页面初始化时的快照,必须重新同步,否则仍传过期 session
this.session = uni.getStorageSync(SESSION);
console.log('[pay] createVirtualOrder session:', this.session);
let params = {
goodsId: this.selected.id,
loginChannel: this.loginChannel,
authType: this.authType,
payChannel: 'WX',
payerSession: this.session,
payScene: this.payScene
};
try {
let { data } = await getOrderInfo(params);
console.log('-------getOrderInfos-------', data);
this.requestVirtualPayment(data);
} catch (e) {
uni.hideLoading();
this.showToast('获取订单信息失败');
}
},
requestVirtualPayment(charge) {
console.log('-------charge-----', charge, {
signData: charge.orderInfo.signData,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment