修改支付跳转参数
This commit is contained in:
@@ -2,10 +2,10 @@
|
|||||||
import { onLaunch, onShow } from '@dcloudio/uni-app'
|
import { onLaunch, onShow } from '@dcloudio/uni-app'
|
||||||
import { captureAppLaunchData } from '/pageSubPack/api/appLaunch.js'
|
import { captureAppLaunchData } from '/pageSubPack/api/appLaunch.js'
|
||||||
|
|
||||||
onLaunch(() => {
|
onLaunch((options) => {
|
||||||
console.log('App 启动')
|
console.log('App 启动', JSON.stringify(options))
|
||||||
// 捕获 App 跳转传入的支付参数(冷启动)
|
// 捕获 App 跳转传入的支付参数(冷启动)
|
||||||
captureAppLaunchData()
|
captureAppLaunchData(options)
|
||||||
|
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
getPushCID()
|
getPushCID()
|
||||||
|
|||||||
@@ -46,3 +46,8 @@ export const getTopupRecordWithStat = (data) => {
|
|||||||
export const postSubscribeAuth = (data) => {
|
export const postSubscribeAuth = (data) => {
|
||||||
return post(`/api/wx/subscribeAuth/auth`, 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 跳转参数处理
|
||||||
* 花开物业 App 通过 path query string 将 token、支付参数传入本中间小程序。
|
* 花开物业 App 通过 launchMiniProgram 的 extraData 传入支付参数和登录凭证,
|
||||||
|
* 小程序通过 referrerInfo.extraData 接收(查询字符串格式)。
|
||||||
*
|
*
|
||||||
* App 传入示例:
|
* extraData 示例:
|
||||||
* pageSubPack/payment-list/arrearsPayment?token=xxx&userId=xxx&payAmount=10&acct=xxx&custId=xxx&sign=xxx&...
|
* payAmount=10&acct=xxx&custId=xxx&token=xxx&userId=xxx&sign=xxx&...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const STORAGE_KEY = 'app_launch_payment_data'
|
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)
|
* 从启动参数中获取 App 传入的全部数据(支付参数 + token + userId)
|
||||||
*/
|
*/
|
||||||
@@ -17,12 +34,23 @@ export function captureAppLaunchData(onShowOptions) {
|
|||||||
const tryGetData = (options, label) => {
|
const tryGetData = (options, label) => {
|
||||||
if (!options) return null
|
if (!options) return null
|
||||||
console.log(label, JSON.stringify(options))
|
console.log(label, JSON.stringify(options))
|
||||||
|
|
||||||
|
// 优先从 query 获取
|
||||||
if (options.query && Object.keys(options.query).length > 0) {
|
if (options.query && Object.keys(options.query).length > 0) {
|
||||||
return options.query
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive } from 'vue'
|
import { ref, reactive } from 'vue'
|
||||||
import { onShow, onLoad } from '@dcloudio/uni-app'
|
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'
|
import { getAppPaymentData, clearAppPaymentData, buildPaymentItemFromApp } from '/pageSubPack/api/appLaunch.js'
|
||||||
|
|
||||||
const paymentItem = reactive({})
|
const paymentItem = reactive({})
|
||||||
@@ -66,12 +68,22 @@ const loadPaymentItem = () => {
|
|||||||
|
|
||||||
const goBack = () => uni.redirectTo({ url: '/pages/paymentIndex/paymentIndex' })
|
const goBack = () => uni.redirectTo({ url: '/pages/paymentIndex/paymentIndex' })
|
||||||
|
|
||||||
const handlePay = () => {
|
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
|
navigatedToPayment.value = true
|
||||||
wx.navigateToMiniProgram({
|
wx.navigateToMiniProgram({
|
||||||
appId: 'wxc0189436c58b59cd',
|
appId: 'wxc0189436c58b59cd',
|
||||||
path: 'pages/pay/pay',
|
path: 'pages/pay/pay',
|
||||||
extraData: { ...paymentItem },
|
extraData: res.data,
|
||||||
envVersion: 'trial',
|
envVersion: 'trial',
|
||||||
success: () => console.log('已跳转到日照银行支付小程序'),
|
success: () => console.log('已跳转到日照银行支付小程序'),
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
@@ -80,7 +92,12 @@ const handlePay = () => {
|
|||||||
uni.showToast({ title: '拉起支付失败', icon: 'none' })
|
uni.showToast({ title: '拉起支付失败', icon: 'none' })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
} catch (err) {
|
||||||
|
uni.hideLoading()
|
||||||
|
showApiError(err)
|
||||||
|
console.error('支付失败:', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleBackToList = () => uni.redirectTo({ url: '/pages/paymentIndex/paymentIndex' })
|
const handleBackToList = () => uni.redirectTo({ url: '/pages/paymentIndex/paymentIndex' })
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user