feat: debug h5
This commit is contained in:
parent
95f58aa70e
commit
309665f49a
14
src/app.tsx
14
src/app.tsx
|
|
@ -1,5 +1,5 @@
|
||||||
import { PropsWithChildren } from 'react'
|
import { PropsWithChildren } from 'react'
|
||||||
import { useLaunch } from '@tarojs/taro'
|
import Taro, { useLaunch, navigateTo } from '@tarojs/taro'
|
||||||
import { Provider } from 'react-redux'
|
import { Provider } from 'react-redux'
|
||||||
import configStore from './store'
|
import configStore from './store'
|
||||||
|
|
||||||
|
|
@ -18,9 +18,19 @@ function App({ children }: PropsWithChildren<any>) {
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
// 可以根据需要决定是否自动跳转登录
|
// 可以根据需要决定是否自动跳转登录
|
||||||
await authorize.login()
|
await authorize.login()
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const result = await payment.pay(`character_figurine_v1`, ``)
|
// 检查是否是支付跳转页面
|
||||||
|
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 })
|
console.log({ result })
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('登录检查失败:', error)
|
console.error('登录检查失败:', error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,27 @@ 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 } = window.location;
|
const { hostname, protocol, port, hash } = 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 cbUrl = `${baseUrl}`
|
const response = await sdk.payTemplateCode(templateCode, imageUrl, `${baseUrl}#/${hash}`)
|
||||||
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,6 +1,7 @@
|
||||||
|
|
||||||
|
|
||||||
export abstract class Payment{
|
export abstract class Payment {
|
||||||
|
|
||||||
abstract pay(templateCode: string, imageUrl: string): Promise<any>;
|
abstract pay(templateCode: string, imageUrl: string): Promise<void>;
|
||||||
|
abstract checkPaymentResult(): Promise<{ paymentId?: string, templateCode?: string }>;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue