Compare commits
No commits in common. "a468dc7dd36ec020a0fb04100b0cf5a27e1d3276" and "e95db8e321a9dc1a8988f612c66891fbfae99d8a" have entirely different histories.
a468dc7dd3
...
e95db8e321
18
src/app.tsx
18
src/app.tsx
|
|
@ -1,5 +1,5 @@
|
||||||
import { PropsWithChildren } from 'react'
|
import { PropsWithChildren } from 'react'
|
||||||
import Taro, { useLaunch, navigateTo } from '@tarojs/taro'
|
import { useLaunch } from '@tarojs/taro'
|
||||||
import { Provider } from 'react-redux'
|
import { Provider } from 'react-redux'
|
||||||
import configStore from './store'
|
import configStore from './store'
|
||||||
|
|
||||||
|
|
@ -21,26 +21,16 @@ function App({ children }: PropsWithChildren<any>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const authorize = createPlatformFactory().createAuthorize()
|
const authorize = createPlatformFactory().createAuthorize()
|
||||||
const payment = createPlatformFactory().createPayment()
|
// const payment = createPlatformFactory().createPayment()
|
||||||
try {
|
try {
|
||||||
// 检查登录状态,包括OAuth 2.0回调处理
|
// 检查登录状态,包括OAuth 2.0回调处理
|
||||||
const isLoggedIn = await authorize.checkLogin()
|
const isLoggedIn = await authorize.checkLogin()
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
// 可以根据需要决定是否自动跳转登录
|
// 可以根据需要决定是否自动跳转登录
|
||||||
await authorize.login()
|
await authorize.login()
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 检查是否是支付跳转页面
|
|
||||||
const paymentResult = await payment.checkPaymentResult()
|
|
||||||
if (paymentResult && paymentResult.paymentId && paymentResult.templateCode) {
|
|
||||||
console.log({ paymentResult })
|
|
||||||
Taro.navigateTo({
|
|
||||||
url: `/pages/result/index?payment_id=${paymentResult.paymentId}`,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const result = await payment.pay(`character_figurine_v1`, `http://gips2.baidu.com/it/u=1674525583,3037683813&fm=3028&app=3028&f=JPEG&fmt=auto?w=1024&h=1024`)
|
|
||||||
console.log({ result })
|
|
||||||
}
|
}
|
||||||
|
// const result = await payment.pay(`character_figurine_v1`, ``)
|
||||||
|
// console.log({ result })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('登录检查失败:', error)
|
console.error('登录检查失败:', error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,27 +3,17 @@ 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 { hostname, protocol, port, hash } = window.location;
|
const { hostname, protocol, port } = window.location;
|
||||||
let baseUrl = `${protocol}//${hostname}`
|
let baseUrl = `${protocol}//${hostname}`
|
||||||
if (hostname === 'localhost') {
|
if (hostname === 'localhost') {
|
||||||
baseUrl = `${protocol}//${hostname}:${port}`
|
baseUrl = `${protocol}//${hostname}:${port}`
|
||||||
}
|
}
|
||||||
const response = await sdk.payTemplateCode(templateCode, imageUrl, `${baseUrl}#/${hash}`)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error(`payment error: ${response}`)
|
throw new Error(`payment error: ${response}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkPaymentResult(): Promise<{ paymentId?: string; templateCode?: string }> {
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
const paymentId = urlParams.get('paymentId') || undefined;
|
|
||||||
const templateCode = urlParams.get('templateCode') || undefined;
|
|
||||||
|
|
||||||
return {
|
|
||||||
paymentId,
|
|
||||||
templateCode
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
export abstract class Payment {
|
export abstract class Payment{
|
||||||
|
|
||||||
abstract pay(templateCode: string, imageUrl: string): Promise<void>;
|
abstract pay(templateCode: string, imageUrl: string): Promise<any>;
|
||||||
abstract checkPaymentResult(): Promise<{ paymentId?: string, templateCode?: string }>;
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue