对接支付
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'; // 生产环境
|
||||
}
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
<template>
|
||||
<view class="contentStyle">
|
||||
<view class="status-bar"></view>
|
||||
<uni-nav-bar :title="paymentItem.type || '缴费'" left-icon="left" @clickLeft="goBack"
|
||||
backgroundColor="transparent" :border="false">
|
||||
</uni-nav-bar>
|
||||
|
||||
<scroll-view class="page" scroll-y="true">
|
||||
<view class="container">
|
||||
<!-- 缴费成功 -->
|
||||
<view v-if="currentStep === 2" class="container">
|
||||
<view class="success-icon"><text class="icon-check">✓</text></view>
|
||||
<view class="title">缴费成功</view>
|
||||
<view class="desc">成功缴纳{{ paymentItem.type || '' }}费用</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<view class="btn-section" v-if="currentStep === 1">
|
||||
<button class="pay-btn" @click="handlePay">立即缴费</button>
|
||||
</view>
|
||||
<view class="btn-section" v-if="currentStep === 2">
|
||||
<button class="pay-btn" @click="handleBackToList">返回</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<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({})
|
||||
const currentStep = ref(1)
|
||||
const navigatedToPayment = ref(false)
|
||||
|
||||
onLoad(() => {
|
||||
const data = loadPaymentItem()
|
||||
Object.assign(paymentItem, data)
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
if (navigatedToPayment.value) {
|
||||
navigatedToPayment.value = false
|
||||
wx.navigateBackApp({
|
||||
success: () => console.log('已返回花开物业 App'),
|
||||
fail: () => {
|
||||
currentStep.value = 2
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const loadPaymentItem = () => {
|
||||
const appData = getAppPaymentData()
|
||||
if (appData) {
|
||||
console.log('检测到 App 跳转参数:', appData)
|
||||
clearAppPaymentData()
|
||||
const item = buildPaymentItemFromApp(appData)
|
||||
uni.setStorageSync('arrearsPayment', item)
|
||||
return item
|
||||
}
|
||||
const stored = uni.getStorageSync('arrearsPayment')
|
||||
return (typeof stored === 'object' && stored !== null) ? stored : {}
|
||||
}
|
||||
|
||||
const goBack = () => uni.redirectTo({ url: '/pages/paymentIndex/paymentIndex' })
|
||||
|
||||
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>
|
||||
|
||||
<style lang="scss">
|
||||
page { background-color: #f9f9f9; }
|
||||
</style>
|
||||
|
||||
<style scoped>
|
||||
.contentStyle { display: flex; flex-direction: column; height: 100vh; background-color: #f9f9f9; }
|
||||
.page { flex: 1; overflow-y: auto; padding: 0 40rpx; box-sizing: border-box; }
|
||||
.btn-section { padding: 20rpx 30rpx 40rpx; }
|
||||
.pay-btn { width: 100%; height: 100rpx; line-height: 100rpx; background-color: #007aff; color: #fff; border-radius: 16rpx; font-size: 32rpx; border: none; }
|
||||
.container { display: flex; flex-direction: column; align-items: center; }
|
||||
.success-icon { width: 220rpx; height: 220rpx; border-radius: 50%; background-color: #1677ff; display: flex; align-items: center; justify-content: center; margin-top: 200rpx; margin-bottom: 60rpx; }
|
||||
.icon-check { color: #fff; font-size: 130rpx; font-weight: bold; }
|
||||
.title { font-size: 40rpx; font-weight: bold; color: #000; margin-bottom: 20rpx; }
|
||||
.desc { font-size: 32rpx; color: #666; text-align: center; margin-bottom: 150rpx; }
|
||||
.status-bar { width: 100vw; height: 46px; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user