This commit is contained in:
Your Name
2026-03-01 14:17:59 +08:00
parent 65aa12f146
commit a07e844c47
6071 changed files with 777651 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
import { PayStatusEnum } from '@/enums/appEnums'
import { handleClientEvent } from '../client'
export class Alipay {
init(name: string, pay: any) {
pay[name] = this
}
openNewPage(options: any) {
uni.navigateBack()
const alipayPage = window.open('', '_self')!
alipayPage.document.body.innerHTML = options
alipayPage.document.forms[0].submit()
}
async run(options: any) {
try {
const res = await handleClientEvent({
H5: () => {
return new Promise((resolve) => {
this.openNewPage(options)
resolve(PayStatusEnum.PENDING)
})
},
OA_WEIXIN: () => {
return new Promise((resolve) => {
this.openNewPage(options)
resolve(PayStatusEnum.PENDING)
})
},
ANDROID: () => {
// const option =
return new Promise((resolve, reject) => {
uni.requestPayment({
provider: 'alipay',
orderInfo: options,
success() {
resolve(PayStatusEnum.SUCCESS)
},
fail() {
resolve(PayStatusEnum.FAIL)
}
})
})
},
IOS: () => {
// const option =
return new Promise((resolve, reject) => {
uni.requestPayment({
provider: 'alipay',
orderInfo: options,
success() {
resolve(PayStatusEnum.SUCCESS)
},
fail() {
resolve(PayStatusEnum.FAIL)
}
})
})
}
})
return res
} catch (error) {
return Promise.reject(error)
}
}
}
+21
View File
@@ -0,0 +1,21 @@
import { Pay } from './pay'
import { Alipay } from './alipay'
import { Wechat } from './wechat'
// 支付方式
enum PayWayEnum {
BALANCE = 1,
WECHAT = 2,
ALIPAY = 3
}
// 注入微信支付
const wechat = new Wechat()
Pay.inject(PayWayEnum[2], wechat)
// 注入支付宝支付
const alipay = new Alipay()
Pay.inject(PayWayEnum[3], alipay)
const pay = new Pay()
export { pay, PayWayEnum }
+28
View File
@@ -0,0 +1,28 @@
import { PayWayEnum } from '.'
export class Pay {
private static modules = new Map()
static inject(name: string, module: any) {
this.modules.set(name, module)
}
constructor() {
//动态注入支付方式
for (const [name, module] of Pay.modules.entries()) {
module.init(name, this)
}
}
//调用支付
async payment(payWay: PayWayEnum, options: any) {
try {
//@ts-ignore
const module = this[PayWayEnum[payWay]]
if (!module) {
throw new Error(`can not find pay way ${payWay}`)
}
return await module.run(options)
} catch (error) {
return Promise.reject(error)
}
}
}
+52
View File
@@ -0,0 +1,52 @@
import { PayStatusEnum } from '@/enums/appEnums'
import { handleClientEvent } from '../client'
//#ifdef H5
import wechatOa from '../wechat'
//#endif
export class Wechat {
init(name: string, pay: any) {
pay[name] = this
}
async run(options: any) {
try {
const res = await handleClientEvent({
MP_WEIXIN: () => {
return new Promise((resolve) => {
uni.requestPayment({
provider: 'wxpay',
...options,
success() {
resolve(PayStatusEnum.SUCCESS)
},
fail() {
resolve(PayStatusEnum.FAIL)
}
})
})
},
OA_WEIXIN: () => {
return new Promise((resolve) => {
wechatOa
.pay(options)
.then(() => {
resolve(PayStatusEnum.SUCCESS)
})
.catch(() => {
resolve(PayStatusEnum.FAIL)
})
})
},
H5: () => {
return new Promise((resolve) => {
window.open(options, '_self')
resolve(PayStatusEnum.PENDING)
})
}
})
return res
} catch (error) {
return Promise.reject(error)
}
}
}