对接支付
This commit is contained in:
@@ -11,10 +11,10 @@ export const getSystemDictData = (data) => {
|
||||
}
|
||||
|
||||
// 查询水电表列表
|
||||
export const getTopUpSelectByResident = (data) => {
|
||||
console.log(data);
|
||||
return get(`/api/topUp/selectByResident/${data.residentUserId}`, data)
|
||||
}
|
||||
// export const getTopUpSelectByResident = (data) => {
|
||||
// console.log(data);
|
||||
// return get(`/api/topUp/selectByResident/${data.residentUserId}`, data)
|
||||
// }
|
||||
// 绑定设备
|
||||
export const getTopUpBindDevice = (data) => {
|
||||
return post(`/api/topUp/bindDevice/${data.deviceCode}/${data.residentUserId}/${data.openid}/${data.deviceType}`,
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
const STORAGE_KEY = 'app_launch_payment_data'
|
||||
const APP_QUERY_KEY = 'app_query_params'
|
||||
|
||||
/**
|
||||
* 解析查询字符串为对象
|
||||
@@ -30,11 +31,18 @@ function parseQueryString(str) {
|
||||
*/
|
||||
export function captureAppLaunchData(onShowOptions) {
|
||||
let data = null
|
||||
let queryData = null
|
||||
|
||||
const tryGetData = (options, label) => {
|
||||
if (!options) return null
|
||||
console.log(label, JSON.stringify(options))
|
||||
|
||||
// 保存 path query 参数(供接口调用)
|
||||
if (options.query && Object.keys(options.query).length > 0) {
|
||||
queryData = options.query
|
||||
console.log(label + ' path query 参数:', JSON.stringify(queryData))
|
||||
}
|
||||
|
||||
// 优先从 query 获取
|
||||
if (options.query && Object.keys(options.query).length > 0) {
|
||||
return options.query
|
||||
@@ -42,7 +50,6 @@ export function captureAppLaunchData(onShowOptions) {
|
||||
|
||||
// referrerInfo.extraData:可能是对象也可能是查询字符串
|
||||
const extraData = options?.referrerInfo?.extraData
|
||||
console.log( ' extraData====',extraData)
|
||||
if (extraData) {
|
||||
if (typeof extraData === 'string') {
|
||||
console.log(label + ' extraData 是查询字符串,解析中...')
|
||||
@@ -64,7 +71,7 @@ export function captureAppLaunchData(onShowOptions) {
|
||||
data = tryGetData(onShowOptions, '热启动')
|
||||
}
|
||||
|
||||
if (data && (data.payAmount || data.acct || data.custId)) {
|
||||
if (data && (data.payAmount || data.acct || data.custId || data.billId)) {
|
||||
// 恢复登录态
|
||||
if (data.token) {
|
||||
uni.setStorageSync('token', data.token)
|
||||
@@ -77,10 +84,16 @@ export function captureAppLaunchData(onShowOptions) {
|
||||
|
||||
uni.setStorageSync(STORAGE_KEY, data)
|
||||
console.log('已存储 App 支付数据:', JSON.stringify(data))
|
||||
return data
|
||||
}
|
||||
|
||||
return null
|
||||
// 单独保存参数供接口使用(优先 queryData,fallback 到 data,即 extraData 来源)
|
||||
const queryParams = queryData || data
|
||||
if (queryParams) {
|
||||
uni.setStorageSync(APP_QUERY_KEY, queryParams)
|
||||
console.log('已存储 App 接口参数:', JSON.stringify(queryParams))
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
/** 检查是否已登录(token 存在) */
|
||||
@@ -93,14 +106,25 @@ export function getAppPaymentData() {
|
||||
try { return uni.getStorageSync(STORAGE_KEY) || null } catch (e) { return null }
|
||||
}
|
||||
|
||||
/** 获取 App 传入的 path query 参数(供接口调用) */
|
||||
export function getAppQueryParams() {
|
||||
try { return uni.getStorageSync(APP_QUERY_KEY) || null } catch (e) { return null }
|
||||
}
|
||||
|
||||
/** 清除 */
|
||||
export function clearAppPaymentData() {
|
||||
uni.removeStorageSync(STORAGE_KEY)
|
||||
}
|
||||
|
||||
/** 清除 path query 参数(在支付完成后调用) */
|
||||
export function clearAppQueryParams() {
|
||||
uni.removeStorageSync(APP_QUERY_KEY)
|
||||
}
|
||||
|
||||
/** 组装 paymentItem */
|
||||
export function buildPaymentItemFromApp(appData) {
|
||||
if (!appData) return null
|
||||
const amount = Number(appData.payAmount || 0).toFixed(2)
|
||||
return { ...appData, type: '缴费', rechargeAmount: amount }
|
||||
const amount = Number(appData.payAmount || appData.orderAmount || 0).toFixed(2)
|
||||
const displayName = appData.goodName || appData.remark || appData.type || '缴费'
|
||||
return { ...appData, type: displayName, rechargeAmount: amount }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
let baseUrl = '';
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
// baseUrl = 'https://wuyeapi.ckdzkj.com'; // 开发环境
|
||||
baseUrl = "https://wuyeapi.bugtc.com"
|
||||
baseUrl = "http://192.168.1.222:8080"
|
||||
} else {
|
||||
baseUrl = 'https://wuyeapi.bugtc.com'; // 生产环境
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user