修改cid无效、登录缓存问题,正在对接支付功能
This commit is contained in:
@@ -135,9 +135,14 @@
|
||||
// 检查是否有从日照银行小程序返回的支付结果
|
||||
if (options && options.referrerInfo && options.referrerInfo.extraData) {
|
||||
const extraData = options.referrerInfo.extraData
|
||||
if (extraData.payResult === 'success') {
|
||||
currentStep.value = 2
|
||||
if (extraData.retCode === 'SUCCESS') {
|
||||
sendPaySuccessPush()
|
||||
uni.redirectTo({
|
||||
url: '/pageSubPack/payment-list/addPaymentSuccess?type=pay'
|
||||
})
|
||||
return
|
||||
} else if (extraData.retCode === 'FAIL') {
|
||||
uni.showToast({ title: extraData.retMsg || '支付失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -145,7 +150,9 @@
|
||||
const paySuccess = uni.getStorageSync('paySuccess')
|
||||
if (paySuccess) {
|
||||
uni.removeStorageSync('paySuccess')
|
||||
currentStep.value = 2
|
||||
uni.redirectTo({
|
||||
url: '/pageSubPack/payment-list/addPaymentSuccess?type=pay'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -174,65 +181,122 @@
|
||||
}
|
||||
|
||||
// 立即缴费 — 通过微信拉起日照银行小程序进行支付
|
||||
const handlePay = async () => {
|
||||
if (!payNum.value || Number(payNum.value) <= 0) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的缴费金额',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
uni.showLoading({ title: '加载中...' })
|
||||
|
||||
// 设备类型映射:电费→1(电表),水费→2(水表)
|
||||
const deviceTypeMap = { '电费': '1', '水费': '2' }
|
||||
const mappedDeviceType = deviceTypeMap[paymentItem.type] || paymentItem.deviceType || ''
|
||||
|
||||
const res = await getBankMiniProgramParams({
|
||||
acct: uni.getStorageSync('userId'), // 用户userId
|
||||
orderType: '20', // 水电费等手输金额
|
||||
orderAmount: String(Math.round(Number(payNum.value) * 100)), // 金额,单位:分
|
||||
deviceCode: paymentItem.deviceCode || '',
|
||||
deviceType: mappedDeviceType, // 1-电表,2-水表
|
||||
billId: paymentItem.billId || '', // 账单明细ID
|
||||
residentUserId: uni.getStorageSync('userId'),
|
||||
goodName: paymentItem.name || '' // 商品名称
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
if (res.code !== 200 || !res.data) {
|
||||
uni.showToast({ title: res.msg || '获取支付参数失败', icon: 'none' })
|
||||
const handlePay = async () => {
|
||||
if (!payNum.value || Number(payNum.value) <= 0) {
|
||||
uni.showToast({
|
||||
title: '请输入正确的缴费金额',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
console.log('resres返回数据',res)
|
||||
console.log('resres',res.data)
|
||||
|
||||
const { appId, path, extraData } = res.data
|
||||
try {
|
||||
uni.showLoading({ title: '加载中...' })
|
||||
|
||||
uni.navigateToMiniProgram({
|
||||
appId: appId,
|
||||
path: path || '',
|
||||
extraData: extraData || {},
|
||||
envVersion: 'release',
|
||||
success: () => {
|
||||
console.log('成功拉起日照银行小程序')
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('拉起日照银行小程序失败', err)
|
||||
uni.showToast({ title: err.msg ||'拉起支付小程序失败', icon: 'none' })
|
||||
// 设备类型映射:电费→1(电表),水费→2(水表)
|
||||
const deviceTypeMap = { '电费': '1', '水费': '2' }
|
||||
const mappedDeviceType = deviceTypeMap[paymentItem.type] || paymentItem.deviceType || ''
|
||||
|
||||
const res = await getBankMiniProgramParams({
|
||||
acct: uni.getStorageSync('userId'),
|
||||
orderType: '20',
|
||||
orderAmount: String(Math.round(Number(payNum.value) * 100)),
|
||||
deviceCode: paymentItem.deviceCode || '',
|
||||
deviceType: mappedDeviceType,
|
||||
billId: paymentItem.billId || '',
|
||||
residentUserId: uni.getStorageSync('userId'),
|
||||
goodName: paymentItem.name || ''
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
if (res.code !== 200 || !res.data) {
|
||||
uni.showToast({ title: res.msg || '获取支付参数失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
uni.hideLoading()
|
||||
console.error('获取支付参数异常', err)
|
||||
uni.showToast({ title: err.msg || '请求异常,请重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
console.log('resres返回数据', res)
|
||||
console.log('resres', res.data)
|
||||
|
||||
// 缴费成功推送通知
|
||||
const { appId, path, extraData } = res.data
|
||||
console.log('navigateToMiniProgram参数:', { appId, path, extraData })
|
||||
|
||||
// 校验必要参数
|
||||
if (!appId) {
|
||||
console.error('缺少appId,无法拉起支付小程序', res.data)
|
||||
uni.showToast({ title: '获取支付参数失败:缺少appId', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 解析 extraData(后端返回可能是字符串或对象)
|
||||
// ' let extraDataObj = extraData
|
||||
// if (typeof extraData === 'string') {
|
||||
// try {
|
||||
// extraDataObj = JSON.parse(extraData)
|
||||
// } catch (e) {
|
||||
// console.error('extraData JSON解析失败,使用空对象', e)
|
||||
// extraDataObj = {}
|
||||
// }
|
||||
// }
|
||||
// if (!extraDataObj || typeof extraDataObj !== 'object') {
|
||||
// extraDataObj = {}
|
||||
// }'
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
// 原生App:通过微信SDK拉起小程序
|
||||
plus.share.getServices((services) => {
|
||||
const weixin = services.find(s => s.id === 'weixin')
|
||||
if (!weixin) {
|
||||
uni.showToast({ title: '未检测到微信客户端', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!weixin.launchMiniProgram) {
|
||||
uni.showToast({ title: '当前微信版本太低,不支持拉起小程序', icon: 'none' })
|
||||
return
|
||||
}
|
||||
weixin.launchMiniProgram({
|
||||
id: appId,
|
||||
type: 1, // 0=正式版 1=测试版 2=预览版
|
||||
path: path || '',
|
||||
extraData: extraData
|
||||
}, (res) => {
|
||||
if (res.retCode === 'SUCCESS') {
|
||||
console.log('成功拉起日照银行小程序(App)', res.retCode)
|
||||
} else {
|
||||
console.log('拉起日照银行小程序返回失败(App======)', res.retMsg)
|
||||
}
|
||||
|
||||
console.log('日照银行小程序回调结果(App)', JSON.stringify(res))
|
||||
}, (err) => {
|
||||
console.error('拉起日照银行小程序失败(App)', JSON.stringify(err))
|
||||
uni.showToast({ title: '拉起支付小程序失败', icon: 'none' })
|
||||
})
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序:直接navigateToMiniProgram
|
||||
uni.navigateToMiniProgram({
|
||||
appId: appId,
|
||||
path: path || '',
|
||||
extraData: extraData,
|
||||
envVersion: 'develop',
|
||||
success: () => {
|
||||
console.log('成功拉起日照银行小程序(微信)')
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('拉起日照银行小程序失败(微信)', JSON.stringify(err))
|
||||
uni.showToast({ title: err.errMsg || err.msg || '拉起支付小程序失败', icon: 'none' })
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
} catch (err) {
|
||||
uni.hideLoading()
|
||||
console.error('获取支付参数异常', err)
|
||||
uni.showToast({ title: err.msg || '请求异常,请重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
// 缴费成功推送通知
|
||||
const sendPaySuccessPush = () => {
|
||||
const userId = uni.getStorageSync('userId')
|
||||
if (userId) {
|
||||
@@ -709,4 +773,4 @@
|
||||
width: 100vw;
|
||||
height: 46px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user