fix: 云闪付SDK改为运行时注入——HBuilderX命令行构建不吃根目录index.html模板(会丢标签),与人脸SDK同款动态加载并带重试兜底
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
45f608c408
commit
bf3bbaa5de
@@ -83,10 +83,22 @@ export default {
|
||||
uni.redirectTo({ url: '/pages/index/login?redirect=' + encodeURIComponent('/pages/venue/detail?id=851219003520709&type=2') })
|
||||
return
|
||||
}
|
||||
this.loadUpSdk() // xuchao: 运行时注入云闪付 SDK(构建模板不可靠,见 loadUpSdk 注释)
|
||||
if (options.orderNo) this.orderNo = options.orderNo
|
||||
this.initFromServer()
|
||||
},
|
||||
methods: {
|
||||
// xuchao: upsdk 运行时注入。不能依赖 index.html 静态标签——HBuilderX 命令行构建的 H5 模板
|
||||
// 不受项目根 index.html 控制(产物会丢标签),与人脸 SDK 同款动态加载兜底。
|
||||
loadUpSdk() {
|
||||
if (typeof window !== 'undefined' && window.upsdk) return
|
||||
if (typeof document === 'undefined') return
|
||||
if (document.querySelector('script[data-upsdk]')) return
|
||||
const s = document.createElement('script')
|
||||
s.src = 'https://open.95516.com/s/open/js/upsdk.js'
|
||||
s.setAttribute('data-upsdk', '1')
|
||||
document.head.appendChild(s)
|
||||
},
|
||||
// xuchao: 价格展示以服务端 latest 为准(测试期 0.01);已有待支付单自动续用;已发券直接跳券详情
|
||||
initFromServer() {
|
||||
this.$u.api.voucherLatest({ phone: this.phone }).then(res => {
|
||||
@@ -135,26 +147,31 @@ export default {
|
||||
},
|
||||
// xuchao: 云闪付控件唤起,交互与湘工惠商城一致(xghmall ordersure.vue:195-229 同型)
|
||||
launchUnionPay(tn) {
|
||||
if (typeof window === 'undefined' || !window.upsdk) {
|
||||
this.submitting = false
|
||||
uni.showToast({ title: '支付组件未就绪,请在云闪付内重进页面', icon: 'none' })
|
||||
return
|
||||
this.loadUpSdk()
|
||||
const tryPay = (retries) => {
|
||||
if (typeof window !== 'undefined' && window.upsdk) {
|
||||
window.upsdk.pluginReady(() => {
|
||||
window.upsdk.pay({
|
||||
tn: tn,
|
||||
success: () => {
|
||||
uni.redirectTo({ url: '/pages/petrol/voucherDetail?orderNo=' + this.orderNo })
|
||||
},
|
||||
fail: () => {
|
||||
this.submitting = false
|
||||
uni.showToast({ title: '支付未完成,可在门店页继续支付', icon: 'none' })
|
||||
}
|
||||
})
|
||||
})
|
||||
// 控件无异步结果时兜底:3 秒后恢复按钮(支付成功路径以回跳/轮询为准)
|
||||
setTimeout(() => { this.submitting = false }, 3000)
|
||||
} else if (retries > 0) {
|
||||
setTimeout(() => tryPay(retries - 1), 500)
|
||||
} else {
|
||||
this.submitting = false
|
||||
uni.showToast({ title: '支付组件加载失败,请在云闪付内重进页面', icon: 'none' })
|
||||
}
|
||||
}
|
||||
const orderNo = this.orderNo
|
||||
window.upsdk.pluginReady(() => {
|
||||
window.upsdk.pay({
|
||||
tn: tn,
|
||||
success: () => {
|
||||
uni.redirectTo({ url: '/pages/petrol/voucherDetail?orderNo=' + orderNo })
|
||||
},
|
||||
fail: () => {
|
||||
this.submitting = false
|
||||
uni.showToast({ title: '支付未完成,可在门店页继续支付', icon: 'none' })
|
||||
}
|
||||
})
|
||||
})
|
||||
// 控件无异步结果时兜底:3 秒后恢复按钮(支付成功路径以回跳/轮询为准)
|
||||
setTimeout(() => { this.submitting = false }, 3000)
|
||||
tryPay(8) // SDK 注入后最多等 4 秒
|
||||
},
|
||||
goBack() {
|
||||
const pages = getCurrentPages()
|
||||
|
||||
Reference in New Issue
Block a user