修改支付跳转参数
This commit is contained in:
@@ -46,3 +46,8 @@ export const getTopupRecordWithStat = (data) => {
|
||||
export const postSubscribeAuth = (data) => {
|
||||
return post(`/api/wx/subscribeAuth/auth`, data)
|
||||
}
|
||||
// 获取日照银行小程序拉起参数
|
||||
export const getBankMiniProgramParams = (data) => {
|
||||
return post('/api/pay/yidang/create', data)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,30 @@
|
||||
/**
|
||||
* App 跳转参数处理
|
||||
* 花开物业 App 通过 path query string 将 token、支付参数传入本中间小程序。
|
||||
* 花开物业 App 通过 launchMiniProgram 的 extraData 传入支付参数和登录凭证,
|
||||
* 小程序通过 referrerInfo.extraData 接收(查询字符串格式)。
|
||||
*
|
||||
* App 传入示例:
|
||||
* pageSubPack/payment-list/arrearsPayment?token=xxx&userId=xxx&payAmount=10&acct=xxx&custId=xxx&sign=xxx&...
|
||||
* extraData 示例:
|
||||
* payAmount=10&acct=xxx&custId=xxx&token=xxx&userId=xxx&sign=xxx&...
|
||||
*/
|
||||
|
||||
const STORAGE_KEY = 'app_launch_payment_data'
|
||||
|
||||
/**
|
||||
* 解析查询字符串为对象
|
||||
*/
|
||||
function parseQueryString(str) {
|
||||
if (!str || typeof str !== 'string') return null
|
||||
const params = {}
|
||||
str.split('&').forEach(item => {
|
||||
const idx = item.indexOf('=')
|
||||
if (idx === -1) return
|
||||
const key = item.substring(0, idx)
|
||||
const val = item.substring(idx + 1)
|
||||
params[key] = decodeURIComponent(val || '')
|
||||
})
|
||||
return params
|
||||
}
|
||||
|
||||
/**
|
||||
* 从启动参数中获取 App 传入的全部数据(支付参数 + token + userId)
|
||||
*/
|
||||
@@ -17,12 +34,23 @@ export function captureAppLaunchData(onShowOptions) {
|
||||
const tryGetData = (options, label) => {
|
||||
if (!options) return null
|
||||
console.log(label, JSON.stringify(options))
|
||||
|
||||
// 优先从 query 获取
|
||||
if (options.query && Object.keys(options.query).length > 0) {
|
||||
return options.query
|
||||
}
|
||||
if (options?.referrerInfo?.extraData) {
|
||||
return options.referrerInfo.extraData
|
||||
|
||||
// referrerInfo.extraData:可能是对象也可能是查询字符串
|
||||
const extraData = options?.referrerInfo?.extraData
|
||||
console.log( ' extraData====',extraData)
|
||||
if (extraData) {
|
||||
if (typeof extraData === 'string') {
|
||||
console.log(label + ' extraData 是查询字符串,解析中...')
|
||||
return parseQueryString(extraData)
|
||||
}
|
||||
return extraData
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue'
|
||||
import { onShow, onLoad } from '@dcloudio/uni-app'
|
||||
import { getBankMiniProgramParams } from '/pageSubPack/api/apiSub.js'
|
||||
import { showApiError } from '/pageSubPack/api/request.js'
|
||||
import { getAppPaymentData, clearAppPaymentData, buildPaymentItemFromApp } from '/pageSubPack/api/appLaunch.js'
|
||||
|
||||
const paymentItem = reactive({})
|
||||
@@ -66,21 +68,36 @@ const loadPaymentItem = () => {
|
||||
|
||||
const goBack = () => uni.redirectTo({ url: '/pages/paymentIndex/paymentIndex' })
|
||||
|
||||
const handlePay = () => {
|
||||
navigatedToPayment.value = true
|
||||
wx.navigateToMiniProgram({
|
||||
appId: 'wxc0189436c58b59cd',
|
||||
path: 'pages/pay/pay',
|
||||
extraData: { ...paymentItem },
|
||||
envVersion: 'trial',
|
||||
success: () => console.log('已跳转到日照银行支付小程序'),
|
||||
fail: (err) => {
|
||||
navigatedToPayment.value = false
|
||||
console.error('跳转日照银行支付失败', err)
|
||||
uni.showToast({ title: '拉起支付失败', icon: 'none' })
|
||||
const handlePay = async () => {
|
||||
uni.showLoading({ title: '加载中...', mask: true })
|
||||
try {
|
||||
// 调用后端获取日照银行支付参数
|
||||
const res = await getBankMiniProgramParams({ ...paymentItem })
|
||||
uni.hideLoading()
|
||||
if (res.code !== 200 || !res.data) {
|
||||
uni.showToast({ title: res.msg || '获取支付参数失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
console.log('支付参数====', JSON.stringify(res.data))
|
||||
navigatedToPayment.value = true
|
||||
wx.navigateToMiniProgram({
|
||||
appId: 'wxc0189436c58b59cd',
|
||||
path: 'pages/pay/pay',
|
||||
extraData: res.data,
|
||||
envVersion: 'trial',
|
||||
success: () => console.log('已跳转到日照银行支付小程序'),
|
||||
fail: (err) => {
|
||||
navigatedToPayment.value = false
|
||||
console.error('跳转日照银行支付失败', err)
|
||||
uni.showToast({ title: '拉起支付失败', icon: 'none' })
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
uni.hideLoading()
|
||||
showApiError(err)
|
||||
console.error('支付失败:', err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const handleBackToList = () => uni.redirectTo({ url: '/pages/paymentIndex/paymentIndex' })
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user