Commit cc0b44ae by Jony.L

新支付功能-api模块支付重构

parent 5a8990ae
......@@ -48,6 +48,7 @@ export function createOrderSubmitWpgj(query){
})
}
export function createPay(query){
return request({
url: '/pay/order/submit',
......
......@@ -54,6 +54,7 @@ export function createApiOrderSubmit(query){
})
}
// === 老的微信支付接口(保留以便回退) ===
export function createPay(query){
return request({
url: '/pay/order/submit',
......@@ -61,3 +62,24 @@ export function createPay(query){
data: query
})
}
// === 新的WPGJ支付接口 ===
// 创建API订单(旺铺聚合支付)
export function createApiOrderSubmitWpgj(query){
return request({
url: '/apihub/api-order/create-wpgj',
method: 'post',
data: query
})
}
// WPGJ旺铺聚合支付订单查询(与算力资源模块共用)
export function getWpgjOrder(id) {
return request({
url: '/pay/order/wpgj-get',
method: 'get',
params: {
id
}
})
}
......@@ -95,7 +95,7 @@
</template>
<script name="ConfirmOrder" setup>
import { confirmOrderInfo, orderSubmit } from '@/api/computingResource.js'
// import { confirmOrderInfo, orderSubmit } from '@/api/computingResource.js'
import { useRoute, useRouter } from 'vue-router'
import { ref } from 'vue'
......@@ -104,19 +104,19 @@ const router = useRouter()
const tableData = ref([])
const totalPrice = ref(0)
const params = ref([])
confirmOrderInfo({id: route.query.id}).then(res => {
totalPrice.value = res.data.publicTotalPrice
params.value = JSON.parse(res.data.param)
tableData.value = [res.data]
})
function submit () {
orderSubmit({id: route.query.id}).then(res => {
if (res.data === 1) {
router.replace('/computingResource/orderResult')
}
})
}
// confirmOrderInfo({id: route.query.id}).then(res => {
// totalPrice.value = res.data.publicTotalPrice
// params.value = JSON.parse(res.data.param)
// tableData.value = [res.data]
// })
// function submit () {
// orderSubmit({id: route.query.id}).then(res => {
// if (res.data === 1) {
// router.replace('/computingResource/orderResult')
// }
// })
// }
</script>
......
......@@ -435,7 +435,7 @@ function create() {
// WPGJ聚合支付处理 - 后端现在直接返回AppPayOrderSubmitRespVO
if (res.data.displayContent) {
// 使用displayContent字段生成二维码,使用WPGJ订单ID进行轮询
getCode(res.data.displayContent, res.data.wpgjOrderId);
getCode(res.data.displayContent, res.data.id);
} else {
ElMessage.error('获取支付信息失败');
}
......
......@@ -259,7 +259,7 @@ import {
//getMerchantInfo,
getAppRecommendList,
//getAppCategoryList,
getAppInfoDetail, createApiOrderSubmit,createPay
getAppInfoDetail, createApiOrderSubmit,createPay, createApiOrderSubmitWpgj, getWpgjOrder
} from "../../api/marketplace";
import {ElMessage, ElMessageBox} from "element-plus";
import { OfficeBuilding, Phone } from '@element-plus/icons-vue'
......@@ -537,8 +537,56 @@ function getCreateData(){
}
function create() {
// 用户点击“确认”时执行
// 用户点击"确认"时执行
const createData = getCreateData();
// === 新的WPGJ支付流程 ===
// 创建API订单(旺铺聚合支付)
createApiOrderSubmitWpgj({
apiId: productData.value.id,
packageId: currentPackageId.value,
}).then(res => {
console.log('API WPGJ支付响应数据:', res.data);
// 弹出确认对话框
ElMessageBox.confirm(
'确定购买吗?', // 对话框提示文字
'购买确认', // 对话框标题
{
confirmButtonText: '确认', // 确认按钮文字
cancelButtonText: '取消', // 取消按钮文字
type: 'warning' // 对话框类型(警告样式)
}
)
.then(() => {
// WPGJ聚合支付处理 - 后端现在直接返回支付信息
if (res.data.displayContent) {
// 使用displayContent字段生成二维码,使用WPGJ订单ID进行轮询
getCodeWpgj(res.data.displayContent, res.data.id);
} else {
ElMessage.error('获取支付信息失败');
}
showDrawer.value = false;
})
.catch(() => {
ElMessageBox.confirm(
'订单已创建,请前往控制台-api订单查看',
'提示',
{
confirmButtonText: '确认',
showCancelButton: false,
type: 'success'
}
).then(() => {
showDrawer.value = false;
})
});
}).catch(err => {
console.error('创建API订单失败:', err);
ElMessage.error('创建订单失败,请重试');
});
// === 老的支付流程代码(注释掉以便回退) ===
/*
//创建订单
createApiOrderSubmit(
{
......@@ -581,25 +629,77 @@ function create() {
}).catch(err => {
// 接口调用失败的处理(如提示错误)
});
*/
}
// === 新的WPGJ支付函数 ===
function getCodeWpgj(value, wpgjOrderId) {
QRCode.toDataURL(value, {errorCorrectionLevel: 'L', margin: 2, width: 350}, (err, url) => {
if (err) throw err
qrCode.value = {
url: url,
title: '请使用微信或支付宝扫码支付',
visible: true
}
}
)
createQueryIntervalWpgj(wpgjOrderId)
}
// === 老的支付函数(注释掉以便回退) ===
/*
function getCode(value, payOrderId) {
QRCode.toDataURL(value, {errorCorrectionLevel: 'L', margin: 2, width: 350}, (err, url) => {
if (err) throw err
qrCode.value = {
url: url,
title: '请使用微信“扫一扫”扫码支付',
title: '请使用微信"扫一扫"扫码支付',
visible: true
}
}
)
createQueryInterval(payOrderId)
}
*/
// === 新的WPGJ轮询查询任务 ===
const createQueryIntervalWpgj = (id) => {
if (interval.value) {
return
}
interval.value = setInterval(async () => {
try {
const res = await getWpgjOrder(id)
console.log(res, 'API WPGJ轮询结果')
// 已支付
if (res.data.orderStatus === '1') {
clearQueryInterval()
ElMessageBox.confirm(
'支付成功',
'请前往控制台-api订单查看',
{
confirmButtonText: '确认',
showCancelButton: false,
type: 'success'
}
).then(() => {})
}
// 已取消或失败
if (res.data.orderStatus === '2') {
clearQueryInterval()
ElMessage.error('支付已关闭!')
}
} catch (e) {
// 静默捕获轮询异常
}
}, 1000 * 2)
}
/** 轮询查询任务 */
// === 老的轮询查询任务(注释掉以便回退) ===
/*
const createQueryInterval = (id) => {
if (interval.value) {
return
......@@ -631,7 +731,10 @@ const createQueryInterval = (id) => {
}
}, 1000 * 2)
}
*/
// === 老的支付订单查询(注释掉以便回退) ===
/*
// 查询详情支付订单
const getOrder = async (id, sync) => {
return await request({
......@@ -643,6 +746,7 @@ const getOrder = async (id, sync) => {
}
})
}
*/
/** 清空查询任务 */
const clearQueryInterval = () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment