对接支付
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,9 +1,9 @@
|
||||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/paymentIndex/paymentIndex",
|
||||
"path": "pages/arrearsPayment/arrearsPayment",
|
||||
"style": {
|
||||
"navigationBarTitleText": "首页",
|
||||
"navigationBarTitleText": "缴费",
|
||||
"navigationStyle": "custom",
|
||||
"navigationBarBackgroundColor": "#F8F8F8"
|
||||
}
|
||||
@@ -73,13 +73,6 @@
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "arrearsPayment",
|
||||
"style": {
|
||||
"navigationBarTitleText": "",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "noArrearsPayment",
|
||||
"style": {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
<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 title="缴费" 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>
|
||||
@@ -20,7 +18,7 @@
|
||||
<button class="pay-btn" @click="handlePay">立即缴费</button>
|
||||
</view>
|
||||
<view class="btn-section" v-if="currentStep === 2">
|
||||
<button class="pay-btn" @click="handleBackToList">返回</button>
|
||||
<button class="pay-btn" @click="handleFinished">完成</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -28,9 +26,9 @@
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue'
|
||||
import { onShow, onLoad } from '@dcloudio/uni-app'
|
||||
import { getAppPaymentData, getAppQueryParams, clearAppPaymentData, buildPaymentItemFromApp } from '/pageSubPack/api/appLaunch.js'
|
||||
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)
|
||||
@@ -42,15 +40,11 @@ onLoad(() => {
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
// 从日照银行支付小程序返回后,显示支付成功页
|
||||
if (navigatedToPayment.value) {
|
||||
navigatedToPayment.value = false
|
||||
wx.navigateBackApp({
|
||||
success: () => console.log('已返回花开物业 App'),
|
||||
fail: () => {
|
||||
currentStep.value = 2
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const loadPaymentItem = () => {
|
||||
@@ -66,26 +60,31 @@ const loadPaymentItem = () => {
|
||||
return (typeof stored === 'object' && stored !== null) ? stored : {}
|
||||
}
|
||||
|
||||
const goBack = () => uni.redirectTo({ url: '/pages/paymentIndex/paymentIndex' })
|
||||
|
||||
const handlePay = async () => {
|
||||
const apiParams = getAppQueryParams()
|
||||
if (!apiParams) {
|
||||
uni.showToast({ title: '支付参数缺失', icon: 'none' })
|
||||
return
|
||||
}
|
||||
delete apiParams.token
|
||||
|
||||
uni.showLoading({ title: '加载中...', mask: true })
|
||||
try {
|
||||
// 调用后端获取日照银行支付参数
|
||||
const res = await getBankMiniProgramParams({ ...paymentItem })
|
||||
const res = await getBankMiniProgramParams(apiParams)
|
||||
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,
|
||||
extraData: res.data.extraData,
|
||||
envVersion: 'trial',
|
||||
success: () => console.log('已跳转到日照银行支付小程序'),
|
||||
success: () => {
|
||||
console.log('已跳转到日照银行支付小程序')
|
||||
},
|
||||
fail: (err) => {
|
||||
navigatedToPayment.value = false
|
||||
console.error('跳转日照银行支付失败', err)
|
||||
@@ -97,9 +96,16 @@ const handlePay = async () => {
|
||||
showApiError(err)
|
||||
console.error('支付失败:', err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleBackToList = () => uni.redirectTo({ url: '/pages/paymentIndex/paymentIndex' })
|
||||
const handleFinished = () => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '请点击右上角关闭按钮返回花开物业',
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
@@ -111,17 +111,17 @@
|
||||
};
|
||||
|
||||
// ===== 获取缴费列表 =====
|
||||
const getPayList = async () => {
|
||||
if (!isLogin.value) return;
|
||||
try {
|
||||
const res = await getTopUpSelectByResident({
|
||||
residentUserId: uni.getStorageSync('userId')
|
||||
})
|
||||
paymentList.value = res.data || []
|
||||
} catch (err) {
|
||||
console.error('列表接口报错:', err)
|
||||
}
|
||||
};
|
||||
// const getPayList = async () => {
|
||||
// if (!isLogin.value) return;
|
||||
// try {
|
||||
// const res = await getTopUpSelectByResident({
|
||||
// residentUserId: uni.getStorageSync('userId')
|
||||
// })
|
||||
// paymentList.value = res.data || []
|
||||
// } catch (err) {
|
||||
// console.error('列表接口报错:', err)
|
||||
// }
|
||||
// };
|
||||
|
||||
// ===== 生命周期 =====
|
||||
onLoad(() => {
|
||||
@@ -155,7 +155,7 @@
|
||||
// 存入 storage 供 arrearsPayment 使用
|
||||
uni.setStorageSync("arrearsPayment", paymentItem)
|
||||
// 直接跳转支付页
|
||||
uni.redirectTo({ url: "/pageSubPack/payment-list/arrearsPayment" })
|
||||
uni.redirectTo({ url: "/pages/arrearsPayment/arrearsPayment" })
|
||||
}
|
||||
|
||||
// ===== 点击事件(统一用 isLogin 判断) =====
|
||||
@@ -185,7 +185,7 @@
|
||||
return;
|
||||
}
|
||||
uni.setStorageSync('arrearsPayment', item)
|
||||
uni.redirectTo({ url: '/pageSubPack/payment-list/arrearsPayment' })
|
||||
uni.redirectTo({ url: '/pages/arrearsPayment/arrearsPayment' })
|
||||
};
|
||||
|
||||
// 点击缴费记录
|
||||
|
||||
Reference in New Issue
Block a user