Compare commits

...

4 Commits

5 changed files with 31 additions and 21 deletions

View File

@ -55,15 +55,26 @@ export default function FriendsPhoto() {
try {
// 将两个图片URL用逗号分隔
const combinedImageUrl = `${image1},${image2}`;
const taskId = await serverSdk.executeTemplate({
imageUrl: combinedImageUrl,
const { hostname, protocol, port } = window.location;
let baseUrl = `${protocol}//${hostname}`
if (hostname === 'localhost') {
baseUrl = `${protocol}//${hostname}:${port}`
}
const cbUrl = `${baseUrl}/result`
const checkout = await serverSdk.createCheckoutSession({
templateCode: templateCode,
metadata: {
cb_url: cbUrl,
imageUrls: [
image1, image2
]
}
});
if (checkout && checkout.url) {
window.location.href = checkout.url;
}
// 跳转到结果页面
navigate(`/result?taskId=${taskId}&templateCode=${templateCode}`);
// navigate(`/result?taskId=${taskId}&templateCode=${templateCode}`);
} catch (error) {
console.error('提交失败:', error);
alert(t('friendsPhoto.waitForTaskCompletion'));

View File

@ -55,7 +55,7 @@ const ResultPage: React.FC = () => {
};
useEffect(() => {
const paymentId = searchParams.get('payment_id') || searchParams.get('taskId');
const paymentId = searchParams.get('paymentId') || searchParams.get('taskId');
if (paymentId) {
setTaskId(paymentId);

View File

@ -1,7 +1,7 @@
import { useServerSdk } from "../../hooks";
import { Payment } from "../types/payment";
export class H5Payment extends Payment {
async pay(templateCode: string, imageUrl: string) {
async pay(templateCode: string, imageUrls: string[]) {
const sdk = useServerSdk()
const { hostname, protocol, port } = window.location;
let baseUrl = `${protocol}//${hostname}`
@ -9,7 +9,7 @@ export class H5Payment extends Payment {
baseUrl = `${protocol}//${hostname}:${port}`
}
const cbUrl = `${baseUrl}`
const response = await sdk.payTemplateCode(templateCode, imageUrl, cbUrl)
const response = await sdk.payTemplateCode(templateCode, imageUrls, cbUrl)
if (response.url) {
window.location.href = response.url;
return;

View File

@ -2,5 +2,5 @@
export abstract class Payment{
abstract pay(templateCode: string, imageUrl: string): Promise<any>;
abstract pay(templateCode: string, imageUrls: string[]): Promise<any>;
}

View File

@ -81,9 +81,9 @@ export interface TaskProgress {
*/
export interface CreateCheckoutParams {
templateCode: string; // 模板代码
userId: string; // 用户ID
metadata: {
imageUrl: string; // 图片URL
imageUrls: string[]; // 图片URL
cb_url: string;
[key: string]: any; // 其他元数据
};
}
@ -129,6 +129,8 @@ export interface GoogleUserInfo {
email: string; // 邮箱
name: string; // 姓名
picture?: string; // 头像URL
customerId?: string;
created?: boolean;
}
/**
@ -370,13 +372,13 @@ export class SdkServer {
/**
* images.join(',')
*/
async payTemplateCode(templateCode: string, imageUrl: string, cbUrl: string) {
async payTemplateCode(templateCode: string, imageUrls: string[], cbUrl: string) {
try {
const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', {
imageUrl: imageUrl,
imageUrls: imageUrls, // 图片URL
cb_url: cbUrl
})
return response.data as {url: string};
return response.data as { url: string };
} catch (error) {
throw error;
}
@ -589,7 +591,7 @@ export class SdkServer {
*/
async profile(): Promise<GoogleUserInfo> {
try {
const response = await this.request<GoogleUserInfo>('/auth/google/userinfo');
const response = await this.request<GoogleUserInfo>('/auth/google/customer');
return response.data;
} catch (error) {
throw error;
@ -638,7 +640,7 @@ export class SdkServer {
if (!uid) {
throw new Error('用户ID不存在');
}
const response = await this.request<{ executions: UserExecution[]; total: number }>(`/templates/executions/user/${uid}`);
const response = await this.request<{ executions: UserExecution[]; total: number }>(`/templates/executions/user`);
return response.data.executions || [];
} catch (error) {
throw error;
@ -660,10 +662,7 @@ export class SdkServer {
*/
async createCheckoutSession(params: CreateCheckoutParams): Promise<CheckoutSessionResult> {
try {
const response = await this.request<CheckoutSessionResult>(`/payment/checkout/${params.templateCode}`, 'POST', {
userId: params.userId,
metadata: params.metadata
});
const response = await this.request<CheckoutSessionResult>(`/payment/checkout/${params.templateCode}`, 'POST', params.metadata);
return response.data;
} catch (error) {
throw error;