This commit is contained in:
iHeyTang 2025-09-28 12:58:51 +08:00
commit df6db4d1b6
3 changed files with 14 additions and 6 deletions

View File

@ -56,10 +56,10 @@ const ResultPage: React.FC = () => {
const instance = getCurrentInstance(); const instance = getCurrentInstance();
const params = instance?.router?.params; const params = instance?.router?.params;
if (params?.taskId) { if (params?.payment_id) {
setTaskId(params.taskId); setTaskId(params.payment_id);
// 开始轮询 // 开始轮询
pollTaskResult(params.taskId); pollTaskResult(params.payment_id);
} else { } else {
showToast({ showToast({
title: '缺少taskId参数', title: '缺少taskId参数',

View File

@ -3,9 +3,16 @@ import { Payment } from "../types/payment";
export class H5Payment extends Payment { export class H5Payment extends Payment {
async pay(templateCode: string, imageUrl: string) { async pay(templateCode: string, imageUrl: string) {
const sdk = useServerSdk() const sdk = useServerSdk()
const response = await sdk.payTemplateCode(templateCode, imageUrl) const { hostname, protocol, port } = window.location;
let baseUrl = `${protocol}//${hostname}`
if (hostname === 'localhost') {
baseUrl = `${protocol}//${hostname}:${port}`
}
const cbUrl = `${baseUrl}`
const response = await sdk.payTemplateCode(templateCode, imageUrl, cbUrl)
if (response.url) { if (response.url) {
window.location.href = response.url; window.location.href = response.url;
return;
} }
throw new Error(`payment error: ${response}`) throw new Error(`payment error: ${response}`)
} }

View File

@ -368,10 +368,11 @@ export class SdkServer {
/** /**
* images.join(',') * images.join(',')
*/ */
async payTemplateCode(templateCode: string, imageUrl: string) { async payTemplateCode(templateCode: string, imageUrl: string, cbUrl: string) {
try { try {
const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', { const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', {
imageUrl: imageUrl imageUrl: imageUrl,
cb_url: cbUrl
}) })
return response.data as {url: string}; return response.data as {url: string};
} catch (error) { } catch (error) {