diff --git a/src/router/daxpay.ts b/src/router/daxpay.ts index 282d435..e6df393 100644 --- a/src/router/daxpay.ts +++ b/src/router/daxpay.ts @@ -27,28 +27,52 @@ export const DaxPayRoute: RouteRecordRaw = { }, }, { - path: '/channel/cashier/:appId', - name: 'ChannelCashier', - component: () => import('@/views/daxpay/cashier/ChannelCashier.vue'), + path: '/cashier/:code', + name: 'CashierCode', + component: () => import('@/views/daxpay/cashier/CashierCode.vue'), meta: { title: '收银台', }, }, { - path: '/alipay/cashier/:appId', - name: 'AlipayCashier', - component: () => import('@/views/daxpay/cashier/alipay/AlipayCashier.vue'), + path: '/cashier/alipay/:code', + name: 'AlipayCashierCode', + component: () => import('@/views/daxpay/cashier/alipay/AlipayCashierCode.vue'), meta: { title: '支付宝收银台', }, }, { - path: '/wechat/cashier/:appId', - name: 'WechatCashier', - component: () => import('@/views/daxpay/cashier/wechat/WechatCashier.vue'), + path: '/cashier/wechat/:code', + name: 'WechatCashierCode', + component: () => import('@/views/daxpay/cashier/wechat/WechatCashierCode.vue'), meta: { title: '微信收银台', }, }, + { + path: '/checkout/:code', + name: 'ChannelCashier', + component: () => import('@/views/daxpay/cashier/ChannelCheckout.vue'), + meta: { + title: '结算台', + }, + }, + { + path: '/alipay/checkout/:appId/:orderId', + name: 'AlipayCashier', + component: () => import('@/views/daxpay/cashier/alipay/AlipayCheckout.vue'), + meta: { + title: '支付宝结算台', + }, + }, + { + path: '/wechat/checkout/:appId/:orderId', + name: 'WechatCheckout', + component: () => import('@/views/daxpay/cashier/wechat/WechatCheckout.vue'), + meta: { + title: '微信结算台', + }, + }, ], } diff --git a/src/views/daxpay/cashier/ChannelCashier.api.ts b/src/views/daxpay/cashier/CashierCode.api.ts similarity index 69% rename from src/views/daxpay/cashier/ChannelCashier.api.ts rename to src/views/daxpay/cashier/CashierCode.api.ts index 7d2c9e1..26f32ac 100644 --- a/src/views/daxpay/cashier/ChannelCashier.api.ts +++ b/src/views/daxpay/cashier/CashierCode.api.ts @@ -2,24 +2,23 @@ import type { AuthResult } from '../auth/ChannelAuth.api' import { http } from '@/utils/http/axios' import type { Result } from '#/axios' - /** - * 获取收银台信息 + * 获取收银台配置信息 */ -export function getCashierInfo(cashierType: string, appId: string) { - return http.request>({ - url: '/unipay/ext/channel/cashier/getCashier', +export function getCashierTypeConfig(cashierType: string, cashierCode: string) { + return http.request>({ + url: '/unipay/cashier/code/findByCashierType', method: 'GET', - params: { cashierType, appId }, + params: { cashierType, cashierCode }, }) } /** * 获取收银台所需授权链接, 用于获取OpenId一类的信息 */ -export function generateAuthUrl(param: CashierAuthParam) { +export function generateAuthUrl(param: CashierAuthUrlParam) { return http.request>({ - url: '/unipay/ext/channel/cashier/generateAuthUrl', + url: '/unipay/cashier/code/generateAuthUrl', method: 'POST', data: param, }) @@ -28,9 +27,9 @@ export function generateAuthUrl(param: CashierAuthParam) { /** * 获取授权信息 */ -export function auth(param: CashierPayParam) { +export function auth(param: CashierAuthParam) { return http.request>({ - url: '/unipay/ext/channel/cashier/auth', + url: '/unipay/cashier/code/auth', method: 'POST', data: param, }) @@ -41,18 +40,28 @@ export function auth(param: CashierPayParam) { */ export function cashierPay(param: CashierPayParam) { return http.request>({ - url: '/unipay/ext/channel/cashier/pay', + url: '/unipay/cashier/code/pay', method: 'POST', data: param, }) } /** - * 通道认证参数 + * 获取认证URL参数 + */ +export interface CashierAuthUrlParam { + // 应用号 + cashierCode?: string + // 收银台类型 + cashierType?: string +} + +/** + * 认证参数 */ export interface CashierAuthParam { // 应用号 - appId?: string + cashierCode?: string // 收银台类型 cashierType?: string // 授权码 @@ -64,7 +73,7 @@ export interface CashierAuthParam { */ export interface CashierPayParam { // 应用号 - appId?: string + cashierCode?: string // 收银台类型 cashierType?: string // 支付金额 @@ -79,7 +88,6 @@ export interface CashierPayParam { * 支付结果 */ export interface PayResult { - // 支付状态 status: string // 支付参数体 @@ -109,21 +117,17 @@ export interface WxJsapiSignResult { } /** - * 收银台配置信息 + * 收银码牌配置信息 */ -export interface ChannelCashierConfigResult { +export interface CashierTypeConfigResult { // 应用号 appId?: string - // 收银台类型 - cashierType?: string - // 收银台名称 - cashierName?: string + // 码牌名称 + name?: string // 支付通道 channel?: string // 支付方式 payMethod?: string // 是否开启分账 allocation?: boolean - // 自动分账 - autoAllocation?: boolean } diff --git a/src/views/daxpay/cashier/ChannelCashier.vue b/src/views/daxpay/cashier/CashierCode.vue similarity index 72% rename from src/views/daxpay/cashier/ChannelCashier.vue rename to src/views/daxpay/cashier/CashierCode.vue index d97039c..69e5846 100644 --- a/src/views/daxpay/cashier/ChannelCashier.vue +++ b/src/views/daxpay/cashier/CashierCode.vue @@ -6,14 +6,14 @@ import { useRoute } from 'vue-router' import router from '@/router' const route = useRoute() -const { appId } = route.params +const { code } = route.params const ua = navigator.userAgent if (ua.includes('MicroMessenger')) { - router.push({ path: `/wechat/cashier/${appId}`, replace: true }) + router.push({ path: `/cashier/wechat/${code}`, replace: true }) } else if (ua.includes('Alipay')) { - router.push({ path: `/alipay/cashier/${appId}`, replace: true }) + router.push({ path: `/cashier/alipay/${code}`, replace: true }) } else { router.push({ name: 'ErrorResult', query: { msg: '请使用支付宝、微信等支付程序进行扫码支付' }, replace: true }) diff --git a/src/views/daxpay/cashier/ChannelCheckout.vue b/src/views/daxpay/cashier/ChannelCheckout.vue new file mode 100644 index 0000000..958e4b4 --- /dev/null +++ b/src/views/daxpay/cashier/ChannelCheckout.vue @@ -0,0 +1,24 @@ + + + + + diff --git a/src/views/daxpay/cashier/alipay/AlipayCashier.vue b/src/views/daxpay/cashier/alipay/AlipayCashierCode.vue similarity index 88% rename from src/views/daxpay/cashier/alipay/AlipayCashier.vue rename to src/views/daxpay/cashier/alipay/AlipayCashierCode.vue index 10cc33e..387f65f 100644 --- a/src/views/daxpay/cashier/alipay/AlipayCashier.vue +++ b/src/views/daxpay/cashier/alipay/AlipayCashierCode.vue @@ -2,7 +2,7 @@
- {{ cashierInfo.cashierName || '支付宝收银台' }} + {{ cashierTypeConfig.name || '支付宝收银台' }}

@@ -65,23 +65,23 @@ import { useRoute } from 'vue-router' import { showNotify } from 'vant' import type { CashierPayParam, - ChannelCashierConfigResult, -} from '@/views/daxpay/cashier/ChannelCashier.api' + CashierTypeConfigResult, +} from '@/views/daxpay/cashier/CashierCode.api' import { cashierPay, - getCashierInfo, -} from '@/views/daxpay/cashier/ChannelCashier.api' + getCashierTypeConfig, +} from '@/views/daxpay/cashier/CashierCode.api' import { CashierTypeEnum } from '@/enums/daxpay/DaxPayEnum' import router from '@/router' import { useKeyboard } from '@/hooks/daxpay/useKeyboard' const route = useRoute() -const { appId } = route.params +const { code } = route.params const showRemark = ref(false) const loading = ref(false) -const cashierInfo = ref({}) +const cashierTypeConfig = ref({}) const amount = ref('0') const description = ref('') @@ -95,8 +95,8 @@ onMounted(() => { * 初始化数据 */ function initData() { - getCashierInfo(CashierTypeEnum.ALIPAY, appId as string).then(({ data }) => { - cashierInfo.value = data + getCashierTypeConfig(CashierTypeEnum.ALIPAY, code as string).then(({ data }) => { + cashierTypeConfig.value = data }).catch((res) => { router.push({ name: 'ErrorResult', query: { msg: res.message } }) }) @@ -114,7 +114,7 @@ function pay() { loading.value = true const from = { amount: amountValue, - appId, + cashierCode: code, cashierType: CashierTypeEnum.ALIPAY, description: description.value, } as CashierPayParam diff --git a/src/views/daxpay/cashier/alipay/AlipayCheckout.vue b/src/views/daxpay/cashier/alipay/AlipayCheckout.vue new file mode 100644 index 0000000..f45a085 --- /dev/null +++ b/src/views/daxpay/cashier/alipay/AlipayCheckout.vue @@ -0,0 +1,111 @@ + + + + + diff --git a/src/views/daxpay/cashier/wechat/WechatCashier.vue b/src/views/daxpay/cashier/wechat/WechatCashierCode.vue similarity index 84% rename from src/views/daxpay/cashier/wechat/WechatCashier.vue rename to src/views/daxpay/cashier/wechat/WechatCashierCode.vue index dce56b3..ff918f3 100644 --- a/src/views/daxpay/cashier/wechat/WechatCashier.vue +++ b/src/views/daxpay/cashier/wechat/WechatCashierCode.vue @@ -2,7 +2,7 @@

- {{ cashierInfo.cashierName || '微信收银台' }} + {{ cashierTypeConfig.cashierName || '微信收银台' }}

@@ -66,38 +66,37 @@ import { showNotify } from 'vant' import type { CashierAuthParam, CashierPayParam, - ChannelCashierConfigResult, + CashierTypeConfigResult, WxJsapiSignResult, -} from '@/views/daxpay/cashier/ChannelCashier.api' +} from '@/views/daxpay/cashier/CashierCode.api' import { auth , cashierPay, generateAuthUrl, - getCashierInfo, -} from '@/views/daxpay/cashier/ChannelCashier.api' + getCashierTypeConfig, +} from '@/views/daxpay/cashier/CashierCode.api' import { CashierTypeEnum } from '@/enums/daxpay/DaxPayEnum' import router from '@/router' import { useKeyboard } from '@/hooks/daxpay/useKeyboard' const route = useRoute() -const { appId } = route.params -const { code } = route.query +const { code } = route.params +const { code : authCode } = route.query const show = ref(false) const showRemark = ref(false) const loading = ref(false) -const cashierInfo = ref({}) +const cashierTypeConfig = ref({}) const amount = ref('0') const description = ref('') const openId = ref('') // 认证参数 const authParam = ref({ - appId: appId as string, - cashierType: CashierTypeEnum.WECHAT_PAY, + code: code as string, + type: CashierTypeEnum.WECHAT_PAY, }) - const { input, del } = useKeyboard(amount) onMounted(() => { @@ -105,13 +104,13 @@ onMounted(() => { }) /** - * 初始化 + * 进入页面的初始化 */ function init() { - // 如果不是重定向跳转过来, 跳转到到重定向地址 - if (!code) { + // 如果不是重定向跳转过来, 跳转到到重定向授权地址 + if (!authCode) { // 重定向跳转到微信授权地址 - generateAuthUrl(authParam.value).then((res) => { + generateAuthUrl({ cashierType: CashierTypeEnum.WECHAT_PAY, cashierCode: code as string}).then((res) => { const url = res.data location.replace(url) }).catch((res) => { @@ -119,7 +118,7 @@ function init() { }) } else { - authParam.value.authCode = code as string + authParam.value.authCode = authCode as string // 初始化数据 initData() } @@ -130,11 +129,14 @@ function init() { */ function initData() { show.value = true - getCashierInfo(CashierTypeEnum.ALIPAY, appId as string).then(({ data }) => { - cashierInfo.value = data + // 获取配置参数 + getCashierTypeConfig(CashierTypeEnum.WECHAT_PAY, code as string).then(({ data }) => { + cashierTypeConfig.value = data }).catch((res) => { router.push({ name: 'ErrorResult', query: { msg: res.message } }) }) + + // 认证获取OpenId auth(authParam.value).then(({ data }) => { openId.value = data.openId as string }).catch((res) => { @@ -154,8 +156,8 @@ function pay() { loading.value = true const from = { + cashierCode: code, amount: amountValue, - appId, openId: openId.value, cashierType: CashierTypeEnum.WECHAT_PAY, description: description.value, diff --git a/src/views/daxpay/cashier/wechat/WechatCheckout.vue b/src/views/daxpay/cashier/wechat/WechatCheckout.vue new file mode 100644 index 0000000..0a8d203 --- /dev/null +++ b/src/views/daxpay/cashier/wechat/WechatCheckout.vue @@ -0,0 +1,11 @@ + + + + +