diff --git a/.env b/.env index ef77492..473df22 100644 --- a/.env +++ b/.env @@ -18,11 +18,11 @@ VITE_OAUTH2_APP_CLIENT='mini:mini' # 是否开启websocket 消息接受, VITE_WEBSOCKET_ENABLE = true # --------------------------- start 开发环境 start ---------------------------------- -VITE_APP_DEV_SERVICE = https://www.zianxin.com/api -# VITE_APP_DEV_SERVICE = https://dzc-test-1.fy.takin.cc +# VITE_APP_DEV_SERVICE = https://www.zianxin.com/api +VITE_APP_DEV_SERVICE = https://dzc-test-1.fy.takin.cc -VITE_IMAGE_DEV_PATH = https://www.zianxin.com/api -# VITE_IMAGE_DEV_PATH = https://dzc-test-1.fy.takin.cc +# VITE_IMAGE_DEV_PATH = https://www.zianxin.com/api +VITE_IMAGE_DEV_PATH = https://dzc-test-1.fy.takin.cc # ----------------------------- end 开发环境 end ------------------------------------ # --------------------------- start 生产环境 start ---------------------------------- diff --git a/src/manifest.json b/src/manifest.json index 35637f4..d682f93 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -21,7 +21,8 @@ }, /* 模块配置 */ "modules" : { - "Push" : {} + "Push" : {}, + "Payment" : {} }, /* 应用发布信息 */ "distribute" : { @@ -84,6 +85,11 @@ } } } + }, + "payment" : { + "alipay" : { + "__platform__" : [ "ios", "android" ] + } } }, "icons" : { diff --git a/src/pages/wallet/list.vue b/src/pages/wallet/list.vue index d4f930f..94fdc6a 100644 --- a/src/pages/wallet/list.vue +++ b/src/pages/wallet/list.vue @@ -184,7 +184,7 @@ const doTransferMoney = (v: any) => { @tap.stop="openFreezeDialog(v)"> 申请冻结 - 去充值 diff --git a/src/pages/wallet/recharge.vue b/src/pages/wallet/recharge.vue index 44a07f2..54ff1ef 100644 --- a/src/pages/wallet/recharge.vue +++ b/src/pages/wallet/recharge.vue @@ -4,19 +4,32 @@ import { onLoad, onShow } from "@dcloudio/uni-app" import { isEmpty } from "radash" import { hooks, constant } from "@@/index" -import { walletApi, payApi } from "@@/api" +import { walletApi, payApi, appPlusPlatformApi, type AppPlusPayDto } from "@@/api" const data = { payType: [ - // { text: "模拟支付", disabled: false, type: "0", value: "mock" }, - { text: "微信支付", disabled: true, type: "1", value: "wx_pub" }, - { text: "支付宝支付", disabled: true, type: "2", value: "alipay_wap" }, + { + logoDir: "/static/pay/wechat-pay.jpg", + text: "微信支付", + desc: "", + disabled: false, + type: "10", + value: "WECHAT" + }, + { + logoDir: "/static/pay/ali-pay.png", + text: "支付宝支付", + desc: "10亿用户都在用,真安全,更放心", + disabled: false, + type: "20", + value: "ALI_PAY" + }, ], } const state = reactive({ walletId: null, - currentPayType: null, + currentPayType: "10", currentRecharge: 0, userInfo: {}, detail: {}, @@ -51,6 +64,7 @@ const getRechargeList = async () => { const { data } = await walletApi.rechargeList(_pa) state.rechargeList = data } +// 充值 const doPay = async () => { if (state.currentRecharge == -1) { uni.showToast({ title: "请选择充值金额", icon: "none" }) @@ -62,31 +76,60 @@ const doPay = async () => { } try { uni.showLoading({ title: "充值中...", mask: true }) - const targetRecharge = state.rechargeList[state.currentRecharge] - const targetPayType = data.payType[state.currentPayType] - if (isEmpty(targetRecharge)) throw new Error() - const _pa = { - payPrice: targetRecharge.payPrice, - walletId: state.walletId, - packageId: targetRecharge.id, - } - const { data: createData, code: createCode }: any = await walletApi.recharge(_pa) - console.log(createCode, "createCode") - if (createCode != 0) throw new Error() - const _payPa = { - id: createData.payOrderId, - walletId: state.walletId, - channelCode: targetPayType.value, - channelExtras: {}, + const targetRecharge = state.rechargeList[state.currentRecharge] + + const targetPayType = data.payType.find(v => v.type == state.currentPayType) + + if (isEmpty(targetRecharge)) { + throw new Error() } - getDetail() + + // 检查用户是否有支付环境 + const pRes = await uni.getProvider({ service: 'payment' }) + const providers = (pRes?.provider ?? []) as string[] + if (!providers.length) { + throw new Error() + } + if (targetPayType!.value == "WECHAT") { + if (!providers.includes("wxpay")) { + uni.showToast({ title: "微信支付环境错误", icon: "none" }) + return + } + } else if (targetPayType!.value == "ALI_PAY") { + if (!providers.includes("alipay")) { + uni.showToast({ title: "支付宝支付环境错误", icon: "none" }) + return + } + } else { + throw new Error() + } + const payParams: AppPlusPayDto = { + bizType: "MINI_APP_WALLET_RECHARGE", + bizId: targetRecharge.id, + miniPlatformType: targetPayType!.value, + openId: "", + } + const { data: createData, code: createCode }: any = await appPlusPlatformApi.miniPay(payParams) + + if (createCode != 0) { + throw new Error(createData?.msg ?? "充值失败") + } + const paymentResult = await uni.requestPayment({ + provider: targetPayType!.value == "WECHAT" ? 'wxpay' : 'alipay', + ...createData?.appPlusPayParams ?? {}, + }); + console.log("paymentResult:", paymentResult); + uni.hideLoading() - uni.showToast({ title: "充值成功", icon: "none" }) - } catch (error) { - console.error(error) + } catch (error: any) { + console.error("充值意外的错误:", error) uni.hideLoading() - uni.showToast({ title: "充值失败", icon: "none" }) + if (error?.errMsg && error?.errMsg.includes("requestPayment:fail [paymentAlipay:62009]unknown error")) { + uni.showToast({ title: "请先安装支付宝App", icon: "none" }) + } else { + uni.showToast({ title: "充值失败", icon: "none" }) + } } } @@ -116,11 +159,18 @@ const doPay = async () => { 支付 - - - - + + + + + + {{ v.text }} + {{ v.desc }} + + + + diff --git a/src/sheep/api/app-plus-platform.ts b/src/sheep/api/app-plus-platform.ts new file mode 100644 index 0000000..f578a19 --- /dev/null +++ b/src/sheep/api/app-plus-platform.ts @@ -0,0 +1,44 @@ +import request from "@/sheep/utils/request" + +export type AutoAdminLoginDto = { + miniPlatformType?: string + phoneCode?: string + userCode?: string +} + +export type GetUniqueCodeDto = { + miniPlatformType?: string + code: string + userId?: string +} + +export type AppPlusPayDto = { + bizType: "MINI_APP_WALLET_RECHARGE" + bizId: string + miniPlatformType: string + amount?: number + openId: string +} + +export default { + autoAdminLogin: (data: AutoAdminLoginDto) => + request({ + url: "/third/third-app-oath/auto-admin-login", + method: "POST", + data, + }), + + getUniqueCode: (data: GetUniqueCodeDto) => + request({ + url: "/third/third-app-oath/get-unique", + method: "POST", + data, + }), + + miniPay: (data: AppPlusPayDto) => + request({ + url: "/third/third-app-pay/app/pay", + method: "POST", + data, + }), +} diff --git a/src/sheep/api/index.ts b/src/sheep/api/index.ts index 1a1341c..7e22e0b 100644 --- a/src/sheep/api/index.ts +++ b/src/sheep/api/index.ts @@ -2,6 +2,8 @@ export { default as accessStatsApi } from "./access-stats" export { default as actCancelApi } from "./act-cancel" export { default as deliveryApi } from "./delivery" export { default as adApi } from "./ad" +export { default as appPlusPlatformApi } from "./app-plus-platform" +export * from "./app-plus-platform" export { default as appVersionApi } from "./app-version" export { default as boxesApi } from "./boxes" export { default as canteenDeliveryApi } from "./canteen-delivery" diff --git a/src/static/pay/ali-pay.png b/src/static/pay/ali-pay.png new file mode 100644 index 0000000..44839a9 Binary files /dev/null and b/src/static/pay/ali-pay.png differ diff --git a/src/static/pay/wechat-pay.jpg b/src/static/pay/wechat-pay.jpg new file mode 100644 index 0000000..fafcaec Binary files /dev/null and b/src/static/pay/wechat-pay.jpg differ