This commit is contained in:
iHeyTang 2025-09-28 11:49:42 +08:00
commit 637cfc5b95
7 changed files with 79 additions and 3 deletions

View File

@ -53,6 +53,7 @@
"dependencies": {
"@babel/runtime": "^7.24.4",
"@reduxjs/toolkit": "^2.9.0",
"@stripe/stripe-js": "^7.9.0",
"@tarojs/components": "4.1.6",
"@tarojs/helper": "4.1.6",
"@tarojs/plugin-framework-react": "4.1.6",

View File

@ -14,6 +14,9 @@ importers:
'@reduxjs/toolkit':
specifier: ^2.9.0
version: 2.9.0(react-redux@9.2.0(@types/react@18.3.24)(react@18.3.1)(redux@5.0.1))(react@18.3.1)
'@stripe/stripe-js':
specifier: ^7.9.0
version: 7.9.0
'@tarojs/components':
specifier: 4.1.6
version: 4.1.6(@tarojs/helper@4.1.6)(@types/react@18.3.24)(postcss@8.5.6)(rollup@3.29.5)(vue@3.5.21(typescript@5.9.2))
@ -1799,36 +1802,42 @@ packages:
engines: {node: '>= 10.0.0'}
cpu: [arm]
os: [linux]
libc: [glibc]
'@parcel/watcher-linux-arm-musl@2.5.1':
resolution: {integrity: sha512-6E+m/Mm1t1yhB8X412stiKFG3XykmgdIOqhjWj+VL8oHkKABfu/gjFj8DvLrYVHSBNC+/u5PeNrujiSQ1zwd1Q==}
engines: {node: '>= 10.0.0'}
cpu: [arm]
os: [linux]
libc: [musl]
'@parcel/watcher-linux-arm64-glibc@2.5.1':
resolution: {integrity: sha512-LrGp+f02yU3BN9A+DGuY3v3bmnFUggAITBGriZHUREfNEzZh/GO06FF5u2kx8x+GBEUYfyTGamol4j3m9ANe8w==}
engines: {node: '>= 10.0.0'}
cpu: [arm64]
os: [linux]
libc: [glibc]
'@parcel/watcher-linux-arm64-musl@2.5.1':
resolution: {integrity: sha512-cFOjABi92pMYRXS7AcQv9/M1YuKRw8SZniCDw0ssQb/noPkRzA+HBDkwmyOJYp5wXcsTrhxO0zq1U11cK9jsFg==}
engines: {node: '>= 10.0.0'}
cpu: [arm64]
os: [linux]
libc: [musl]
'@parcel/watcher-linux-x64-glibc@2.5.1':
resolution: {integrity: sha512-GcESn8NZySmfwlTsIur+49yDqSny2IhPeZfXunQi48DMugKeZ7uy1FX83pO0X22sHntJ4Ub+9k34XQCX+oHt2A==}
engines: {node: '>= 10.0.0'}
cpu: [x64]
os: [linux]
libc: [glibc]
'@parcel/watcher-linux-x64-musl@2.5.1':
resolution: {integrity: sha512-n0E2EQbatQ3bXhcH2D1XIAANAcTZkQICBPVaxMeaCVBtOpBZpWJuf7LwyWPSBDITb7In8mqQgJ7gH8CILCURXg==}
engines: {node: '>= 10.0.0'}
cpu: [x64]
os: [linux]
libc: [musl]
'@parcel/watcher-win32-arm64@2.5.1':
resolution: {integrity: sha512-RFzklRvmc3PkjKjry3hLF9wD7ppR4AKcWNzH7kXR7GUe0Igb3Nz8fyPwtZCSquGrhU5HhUNDr/mKBqj7tqA2Vw==}
@ -1976,6 +1985,10 @@ packages:
engines: {node: '>=12.10.0', npm: '>=6.0.0'}
hasBin: true
'@stripe/stripe-js@7.9.0':
resolution: {integrity: sha512-ggs5k+/0FUJcIgNY08aZTqpBTtbExkJMYMLSMwyucrhtWexVOEY1KJmhBsxf+E/Q15f5rbwBpj+t0t2AW2oCsQ==}
engines: {node: '>=12.16'}
'@swc/core-darwin-arm64@1.3.96':
resolution: {integrity: sha512-8hzgXYVd85hfPh6mJ9yrG26rhgzCmcLO0h1TIl8U31hwmTbfZLzRitFQ/kqMJNbIBCwmNH1RU2QcJnL3d7f69A==}
engines: {node: '>=10'}
@ -1999,24 +2012,28 @@ packages:
engines: {node: '>=10'}
cpu: [arm64]
os: [linux]
libc: [glibc]
'@swc/core-linux-arm64-musl@1.3.96':
resolution: {integrity: sha512-i5/UTUwmJLri7zhtF6SAo/4QDQJDH2fhYJaBIUhrICmIkRO/ltURmpejqxsM/ye9Jqv5zG7VszMC0v/GYn/7BQ==}
engines: {node: '>=10'}
cpu: [arm64]
os: [linux]
libc: [musl]
'@swc/core-linux-x64-gnu@1.3.96':
resolution: {integrity: sha512-USdaZu8lTIkm4Yf9cogct/j5eqtdZqTgcTib4I+NloUW0E/hySou3eSyp3V2UAA1qyuC72ld1otXuyKBna0YKQ==}
engines: {node: '>=10'}
cpu: [x64]
os: [linux]
libc: [glibc]
'@swc/core-linux-x64-musl@1.3.96':
resolution: {integrity: sha512-QYErutd+G2SNaCinUVobfL7jWWjGTI0QEoQ6hqTp7PxCJS/dmKmj3C5ZkvxRYcq7XcZt7ovrYCTwPTHzt6lZBg==}
engines: {node: '>=10'}
cpu: [x64]
os: [linux]
libc: [musl]
'@swc/core-win32-arm64-msvc@1.3.96':
resolution: {integrity: sha512-hjGvvAduA3Un2cZ9iNP4xvTXOO4jL3G9iakhFsgVhpkU73SGmK7+LN8ZVBEu4oq2SUcHO6caWvnZ881cxGuSpg==}
@ -2092,6 +2109,7 @@ packages:
engines: {node: '>= 18'}
cpu: [x64]
os: [linux]
libc: [glibc]
'@tarojs/binding-win32-x64-msvc@4.1.6':
resolution: {integrity: sha512-jHeQtg3qJLtTdj36CPgiSzfLyEDP0xt1nm9hXSr3LDvsXrp+7Qz6HL4bgbSEFAxLMnHUd7NnTE1Au3WmNOQTkg==}
@ -2169,24 +2187,28 @@ packages:
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
libc: [glibc]
'@tarojs/parse-css-to-stylesheet-linux-arm64-musl@0.0.69':
resolution: {integrity: sha512-bYODGCEx1Ni4EMNuZU95IUPqVZAXsY9gIc5CPSfKQ2j167Vbeo/gskQk/uNVjmnYJ69PplgJ9npylINgLIPIrA==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
libc: [musl]
'@tarojs/parse-css-to-stylesheet-linux-x64-gnu@0.0.69':
resolution: {integrity: sha512-89f03s+txGJ1c8Zc6Ib4qTAP4YhfFbVFq29XExqbC7eGvpQl5DeOtwonO5DBwMc7lA+LG4b1Q4CMXE3qodn2eA==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
libc: [glibc]
'@tarojs/parse-css-to-stylesheet-linux-x64-musl@0.0.69':
resolution: {integrity: sha512-vyewIf1KysXYNIJdkzc9JSPguTG9zD65Belk3H186mLR18KtsvrqNqlWnP8kKfduF4ixh6qt0F2PkKbeI9PZvg==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
libc: [musl]
'@tarojs/parse-css-to-stylesheet-win32-x64-msvc@0.0.69':
resolution: {integrity: sha512-CHKlVjAiSAZTFNV8GkfXV88Jy9yyFSvKBAO3++l2KSQUBUWmPX775FbH+god2BOLf5SfAXRPd0HVAEK9qNeHXQ==}
@ -2226,24 +2248,28 @@ packages:
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
libc: [glibc]
'@tarojs/plugin-doctor-linux-arm64-musl@0.0.13':
resolution: {integrity: sha512-V1HnFITOLgHVyQ+OCa1oPFKOtGFRtP91vlbUGfOwMA4GeOVw9g28W/hfTyucTCkfZWlrssLehgW6L2AGAMXh2w==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
libc: [musl]
'@tarojs/plugin-doctor-linux-x64-gnu@0.0.13':
resolution: {integrity: sha512-oetfzBW60uenPBBF4/NE6Mf0Iwkw1YGqIIBiN++aVQynbWrmMzWBsW8kleZ5vN1npxI9aud9EfRU1uM37DrG2A==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
libc: [glibc]
'@tarojs/plugin-doctor-linux-x64-musl@0.0.13':
resolution: {integrity: sha512-OdIF/kFwwM0kQPDnpkanhvfWRaAI6EtDmpM9rQA/Lu2QcJq86w5d7X/WSN0U2xF1nialAUrfl79NyIaEzp4Fcw==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
libc: [musl]
'@tarojs/plugin-doctor-win32-ia32-msvc@0.0.13':
resolution: {integrity: sha512-nIbG2SliRhRwACLa1kNMskcfjsihp+3tZQMAxl+LoYUq6JRaWgP3vH2nHkDyZHTCheBTDtAaupqXWrYF3w+U6g==}
@ -2681,41 +2707,49 @@ packages:
resolution: {integrity: sha512-34gw7PjDGB9JgePJEmhEqBhWvCiiWCuXsL9hYphDF7crW7UgI05gyBAi6MF58uGcMOiOqSJ2ybEeCvHcq0BCmQ==}
cpu: [arm64]
os: [linux]
libc: [glibc]
'@unrs/resolver-binding-linux-arm64-musl@1.11.1':
resolution: {integrity: sha512-RyMIx6Uf53hhOtJDIamSbTskA99sPHS96wxVE/bJtePJJtpdKGXO1wY90oRdXuYOGOTuqjT8ACccMc4K6QmT3w==}
cpu: [arm64]
os: [linux]
libc: [musl]
'@unrs/resolver-binding-linux-ppc64-gnu@1.11.1':
resolution: {integrity: sha512-D8Vae74A4/a+mZH0FbOkFJL9DSK2R6TFPC9M+jCWYia/q2einCubX10pecpDiTmkJVUH+y8K3BZClycD8nCShA==}
cpu: [ppc64]
os: [linux]
libc: [glibc]
'@unrs/resolver-binding-linux-riscv64-gnu@1.11.1':
resolution: {integrity: sha512-frxL4OrzOWVVsOc96+V3aqTIQl1O2TjgExV4EKgRY09AJ9leZpEg8Ak9phadbuX0BA4k8U5qtvMSQQGGmaJqcQ==}
cpu: [riscv64]
os: [linux]
libc: [glibc]
'@unrs/resolver-binding-linux-riscv64-musl@1.11.1':
resolution: {integrity: sha512-mJ5vuDaIZ+l/acv01sHoXfpnyrNKOk/3aDoEdLO/Xtn9HuZlDD6jKxHlkN8ZhWyLJsRBxfv9GYM2utQ1SChKew==}
cpu: [riscv64]
os: [linux]
libc: [musl]
'@unrs/resolver-binding-linux-s390x-gnu@1.11.1':
resolution: {integrity: sha512-kELo8ebBVtb9sA7rMe1Cph4QHreByhaZ2QEADd9NzIQsYNQpt9UkM9iqr2lhGr5afh885d/cB5QeTXSbZHTYPg==}
cpu: [s390x]
os: [linux]
libc: [glibc]
'@unrs/resolver-binding-linux-x64-gnu@1.11.1':
resolution: {integrity: sha512-C3ZAHugKgovV5YvAMsxhq0gtXuwESUKc5MhEtjBpLoHPLYM+iuwSj3lflFwK3DPm68660rZ7G8BMcwSro7hD5w==}
cpu: [x64]
os: [linux]
libc: [glibc]
'@unrs/resolver-binding-linux-x64-musl@1.11.1':
resolution: {integrity: sha512-rV0YSoyhK2nZ4vEswT/QwqzqQXw5I6CjoaYMOX0TqBlWhojUf8P94mvI7nuJTeaCkkds3QE4+zS8Ko+GdXuZtA==}
cpu: [x64]
os: [linux]
libc: [musl]
'@unrs/resolver-binding-wasm32-wasi@1.11.1':
resolution: {integrity: sha512-5u4RkfxJm+Ng7IWgkzi3qrFOvLvQYnPBmjmZQ8+szTK/b31fQCnleNl1GgEt7nIsZRIf5PLhPwT0WM+q45x/UQ==}
@ -8973,6 +9007,8 @@ snapshots:
'@stencil/core@2.22.3': {}
'@stripe/stripe-js@7.9.0': {}
'@swc/core-darwin-arm64@1.3.96':
optional: true

View File

@ -21,7 +21,7 @@ function App({ children }: PropsWithChildren<any>) {
}
const authorize = createPlatformFactory().createAuthorize()
const payment = createPlatformFactory().createPayment()
try {
// 检查登录状态包括OAuth 2.0回调处理
const isLoggedIn = await authorize.checkLogin()
@ -29,6 +29,8 @@ function App({ children }: PropsWithChildren<any>) {
// 可以根据需要决定是否自动跳转登录
await authorize.login()
}
const result = await payment.pay(`character_figurine_v1`, ``)
console.log({ result })
} catch (error) {
console.error('登录检查失败:', error)
}

View File

@ -5,6 +5,8 @@ import { Authorize } from "./types/index";
import { H5Authorize } from "./h5/index";
import { TtAuthorize } from "./tt/index";
import { WeappAuthorize } from "./weapp/index";
import { H5Payment } from "./h5/payment";
import { Payment } from "./types/payment";
/**
*
@ -101,6 +103,10 @@ export class PlatformFactory {
}
}
createPayment(): Payment {
return new H5Payment()
}
createAuthorize(): Authorize {
switch (this.platform) {
case 'bytedance':

View File

@ -0,0 +1,12 @@
import { useServerSdk } from "../../hooks";
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)
if (response.url) {
window.location.href = response.url;
}
throw new Error(`payment error: ${response}`)
}
}

View File

@ -0,0 +1,6 @@
export abstract class Payment{
abstract pay(templateCode: string, imageUrl: string): Promise<any>;
}

View File

@ -357,7 +357,7 @@ export class SdkServer {
async executeTemplate(params: ExecuteTemplateParams): Promise<ExecuteTemplateResult> {
try {
const response = await this.request<ExecuteTemplateResult>(`/templates/execute/${params.templateCode}`, 'POST', {
userId: params.userId,
// userId: params.userId,
imageUrl: params.imageUrl
});
return response.data;
@ -365,6 +365,19 @@ export class SdkServer {
throw error;
}
}
/**
* images.join(',')
*/
async payTemplateCode(templateCode: string, imageUrl: string) {
try {
const response = await this.request(`/payment/checkout/${templateCode}`, 'POST', {
imageUrl: imageUrl
})
return response.data as {url: string};
} catch (error) {
throw error;
}
}
/**
*
@ -795,7 +808,7 @@ export class SdkServer {
const params = new URLSearchParams();
if (redirectUrl) params.set('redirect_url', redirectUrl);
if (scopes) params.set('scopes', scopes);
const queryString = params.toString();
return `${this.baseUrl}/auth/google/authorize${queryString ? '?' + queryString : ''}`;
}