修改支付跳转参数
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user