feat:支付宝支付
This commit is contained in:
1 parent
55d53def08
commit
f57b6ea7fc
8 files changed
+139
-37
No files matched your search
@@ -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 ----------------------------------
|
||||
|
||||
+7
-1
@@ -21,7 +21,8 @@
|
||||
},
|
||||
/* 模块配置 */
|
||||
"modules" : {
|
||||
"Push" : {}
|
||||
"Push" : {},
|
||||
"Payment" : {}
|
||||
},
|
||||
/* 应用发布信息 */
|
||||
"distribute" : {
|
||||
@@ -84,6 +85,11 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"payment" : {
|
||||
"alipay" : {
|
||||
"__platform__" : [ "ios", "android" ]
|
||||
}
|
||||
}
|
||||
},
|
||||
"icons" : {
|
||||
|
||||
@@ -184,7 +184,7 @@ const doTransferMoney = (v: any) => {
|
||||
@tap.stop="openFreezeDialog(v)">
|
||||
申请冻结
|
||||
</view>
|
||||
<view v-if="false && v.walletTypeUniqueCode == 2" class="botder_btn"
|
||||
<view v-if="v.walletTypeUniqueCode == 1" class="botder_btn"
|
||||
@tap.stop="router.jump('/pages/wallet/recharge', { id: v.id })">
|
||||
去充值
|
||||
</view>
|
||||
|
||||
@@ -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<any>({
|
||||
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" })
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -116,11 +159,18 @@ const doPay = async () => {
|
||||
</view>
|
||||
</view>
|
||||
<view class="prefix_title m-t-35rpx">支付</view>
|
||||
<view class="p-30rpx p-b-40rpx bg-white rounded-20rpx m-t-20rpx shadow-main">
|
||||
<tm-radio-group direction="column" gap="40" v-model="state.currentPayType">
|
||||
<tm-radio :disabled="v.disabled" v-for="(v, i) in data.payType" :key="i" :value="v.type"
|
||||
:label="v.text" />
|
||||
</tm-radio-group>
|
||||
<view class="p-30rpx pb-0! p-b-40rpx bg-white rounded-20rpx m-t-20rpx shadow-main">
|
||||
<view v-for="(v, i) in data.payType" :key="i" class="flex items-center py-24rpx px-10rpx rounded-16rpx"
|
||||
@tap="!v.disabled && (state.currentPayType = v.type)">
|
||||
<image class="size-50rpx" :src="v.logoDir" mode="scaleToFill" />
|
||||
<view class="flex-1 flex justify-between items-center">
|
||||
<view class="flex-col justify-center p-l-30rpx">
|
||||
<view class="sub-text-24">{{ v.text }}</view>
|
||||
<view class="second-text-20">{{ v.desc }}</view>
|
||||
</view>
|
||||
<tm-radio v-model="state.currentPayType" :disabled="v.disabled" :value="v.type" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="bg-#0094ff p-y-20rpx text-center rounded-40rpx m-x-30rpx m-t-60rpx sub-text-30 color-white!"
|
||||
@tap="doPay">
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 124 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
Reference in new issue
Block a user