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 params = instance?.router?.params;
if (params?.taskId) {
setTaskId(params.taskId);
if (params?.payment_id) {
setTaskId(params.payment_id);
// 开始轮询
pollTaskResult(params.taskId);
pollTaskResult(params.payment_id);
} else {
showToast({
title: '缺少taskId参数',

View File

@ -3,9 +3,16 @@ import { Payment } from "../types/payment";
export class H5Payment extends Payment {
async pay(templateCode: string, imageUrl: string) {
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) {
window.location.href = response.url;
return;
}
throw new Error(`payment error: ${response}`)
}

View File

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