Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
account-book
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘文虎
account-book
Commits
c3f88e03
You need to sign in or sign up before continuing.
Commit
c3f88e03
authored
Jul 23, 2026
by
李超鹏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复sessionKey过期问题
parent
4bf622b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
5 deletions
+58
-5
pay.vue
pages/mine/pay/pay.vue
+58
-5
No files found.
pages/mine/pay/pay.vue
View file @
c3f88e03
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment