|
|
@@ -14,6 +14,7 @@ import {
|
|
|
PaymentRateLimiter,
|
|
|
retryPayment
|
|
|
} from '@/utils/payment'
|
|
|
+import { paymentClient } from '@/api'
|
|
|
|
|
|
interface PaymentPageParams {
|
|
|
orderId: number
|
|
|
@@ -57,17 +58,31 @@ const PaymentPage = () => {
|
|
|
queryFn: async () => {
|
|
|
if (!params?.orderId) throw new Error('订单ID无效')
|
|
|
|
|
|
- // 这里应该调用后端API获取微信支付参数
|
|
|
- // 暂时模拟返回支付参数
|
|
|
- const mockPaymentData: PaymentData = {
|
|
|
- timeStamp: Math.floor(Date.now() / 1000).toString(),
|
|
|
- nonceStr: Math.random().toString(36).substring(2, 15),
|
|
|
- package: 'prepay_id=wx' + Math.random().toString(36).substring(2, 15),
|
|
|
- signType: 'RSA',
|
|
|
- paySign: 'mock_sign_' + Math.random().toString(36).substring(2, 15)
|
|
|
+ // 调用后端API获取微信支付参数
|
|
|
+ const response = await paymentClient.payment.$post({
|
|
|
+ json: {
|
|
|
+ orderId: params.orderId,
|
|
|
+ totalAmount: Math.round(params.amount * 100), // 转换为分
|
|
|
+ description: `订单支付 - ${params.orderNo || `ORD${params.orderId}`}`
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ if (response.status !== 200) {
|
|
|
+ throw new Error(`获取支付参数失败: ${response.status}`)
|
|
|
+ }
|
|
|
+
|
|
|
+ const responseData = await response.json()
|
|
|
+
|
|
|
+ // 转换响应数据格式
|
|
|
+ const paymentData: PaymentData = {
|
|
|
+ timeStamp: responseData.timeStamp,
|
|
|
+ nonceStr: responseData.nonceStr,
|
|
|
+ package: responseData.package,
|
|
|
+ signType: responseData.signType,
|
|
|
+ paySign: responseData.paySign
|
|
|
}
|
|
|
|
|
|
- return mockPaymentData
|
|
|
+ return paymentData
|
|
|
},
|
|
|
enabled: !!params?.orderId && paymentStatus === PaymentStatus.PENDING
|
|
|
})
|