Merge branch 'master' of https://gitea.bowongai.com/bowong/bw-mini-app
This commit is contained in:
commit
df6db4d1b6
|
|
@ -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参数',
|
||||
|
|
|
|||
|
|
@ -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}`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue