feat: 质惠游 H5 一期 —— 门票模块全链路(微信公众号版)
从 xghmall(云闪付版湘工游)迁移民票模块,改造为微信公众号 H5: - 技术栈沿用 uni-app + Vue2 + uView(含定制版日历组件) - 登录/支付独立成层(common/auth.js、common/pay.js): 一期假登录(测试手机号)+ 模拟支付,后端微信接口就绪后只换这两处 - 登录页重写:短信验证码 + 公众号网页授权(code 换用户信息)预留 - 门票列表页为入口页(进页必须登录),加订单悬浮按钮 - 支付成功页接通:查看订单/继续逛逛 + 订单状态轮询 - 详情页定位导航改用 uni.openLocation + 高德网页兜底 - 出行人页:身份证 18 位格式校验,删除死的删除按钮,修正证件类型回显笔误 - 清理云闪付 SDK、支付宝授权、死页面引用等残留 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
// xuchao: 支付层 —— 支付逻辑全部隔离在这里
|
||||
// 一期为模拟支付(开发模式),后端微信预下单接口就绪后只改本文件:
|
||||
// - devMode=true 模拟支付成功(订单在测试环境真实生成为"待支付"状态)
|
||||
// - devMode=false 调后端微信预下单接口,再用微信内置桥接唤起微信支付
|
||||
import config from '@/common/config.js'
|
||||
|
||||
// xuchao: 判断是否在微信浏览器内(正式支付只能在微信里唤起)
|
||||
const isWechatBrowser = () => {
|
||||
// #ifdef H5
|
||||
return /micromessenger/i.test(navigator.userAgent)
|
||||
// #endif
|
||||
}
|
||||
|
||||
// xuchao: 发起支付
|
||||
// vm: 页面的 this(用于调接口)
|
||||
// orderId: 订单号(createTicketsOrder 返回值)
|
||||
// onSuccess / onFail: 支付结果回调
|
||||
const pay = (vm, { orderId, onSuccess, onFail }) => {
|
||||
if (config.devMode) {
|
||||
// 开发模式:模拟支付成功
|
||||
uni.showLoading({ title: '支付中...' })
|
||||
setTimeout(() => {
|
||||
uni.hideLoading()
|
||||
onSuccess && onSuccess({ mock: true })
|
||||
}, 800)
|
||||
return
|
||||
}
|
||||
|
||||
// 正式流程:微信 JSAPI 支付
|
||||
if (!isWechatBrowser()) {
|
||||
uni.showToast({ icon: 'none', title: '请在微信中打开完成支付' })
|
||||
onFail && onFail({ errMsg: 'not wechat browser' })
|
||||
return
|
||||
}
|
||||
const openId = uni.getStorageSync('openId')
|
||||
vm.$u.api.prepayWx({ orderId, openId }).then(res => {
|
||||
if (!res) return
|
||||
const p = res.data || {}
|
||||
// 后端返回微信支付所需参数后,用此桥接唤起支付(微信浏览器内置,无需额外引入)
|
||||
WeixinJSBridge.invoke('getBrandWCPayRequest', {
|
||||
appId: p.appId,
|
||||
timeStamp: String(p.timeStamp),
|
||||
nonceStr: p.nonceStr,
|
||||
package: p.pack || p.packageValue,
|
||||
signType: p.signType || 'RSA',
|
||||
paySign: p.paySign
|
||||
}, bridgeRes => {
|
||||
if (bridgeRes.err_msg === 'get_brand_wcpay_request:ok') {
|
||||
onSuccess && onSuccess(bridgeRes)
|
||||
} else {
|
||||
onFail && onFail(bridgeRes)
|
||||
}
|
||||
})
|
||||
}).catch(() => {
|
||||
onFail && onFail({ errMsg: 'prepay error' })
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
pay,
|
||||
isWechatBrowser
|
||||
}
|
||||
Reference in New Issue
Block a user