From a96441949a552673af587c5de7b8fbb4e5db824b Mon Sep 17 00:00:00 2001 From: DaxPay Date: Mon, 30 Sep 2024 17:52:51 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=94=B6=E9=93=B6=E5=8F=B0=E8=B0=83?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 2 + src/router/daxpay.ts | 2 +- src/utils/http/axios/index.ts | 32 ++-------- src/views/daxpay/channel/ChannelAuth.api.ts | 15 ++++- .../daxpay/channel/ChannelCashier.api.ts | 24 ++++++-- src/views/daxpay/channel/ChannelCashier.vue | 38 +----------- .../channel/alipay/cashier/AlipayCashier.vue | 33 +++++----- .../channel/wechat/cashier/WechatCashier.vue | 60 +++++++++++++------ 8 files changed, 104 insertions(+), 102 deletions(-) diff --git a/components.d.ts b/components.d.ts index b68051a..5629e63 100644 --- a/components.d.ts +++ b/components.d.ts @@ -10,10 +10,12 @@ declare module 'vue' { Loading: typeof import('./src/components/Loading.vue')['default'] Logo: typeof import('./src/components/Logo.vue')['default'] SvgIcon: typeof import('./src/components/SvgIcon.vue')['default'] + VanButton: typeof import('vant/es')['Button'] VanConfigProvider: typeof import('vant/es')['ConfigProvider'] VanDialog: typeof import('vant/es')['Dialog'] VanField: typeof import('vant/es')['Field'] VanLoading: typeof import('vant/es')['Loading'] VanNumberKeyboard: typeof import('vant/es')['NumberKeyboard'] + VanTextEllipsis: typeof import('vant/es')['TextEllipsis'] } } diff --git a/src/router/daxpay.ts b/src/router/daxpay.ts index d873118..f8dcba8 100644 --- a/src/router/daxpay.ts +++ b/src/router/daxpay.ts @@ -27,7 +27,7 @@ export const DaxPayRoute: RouteRecordRaw = { }, }, { - path: '/channel/cashier/:appId/:channel', + path: '/channel/cashier/:mchNo/:appId', name: 'ChannelCashier', component: () => import('@/views/daxpay/channel/ChannelCashier.vue'), meta: { diff --git a/src/utils/http/axios/index.ts b/src/utils/http/axios/index.ts index 1a084b7..bcdf294 100644 --- a/src/utils/http/axios/index.ts +++ b/src/utils/http/axios/index.ts @@ -91,34 +91,12 @@ const transform: AxiosTransform = { return result } // 接口请求错误,统一提示错误信息 这里逻辑可以根据项目进行修改 - let errorMsg = msg + const errorMsg = msg - switch (code) { - // 请求失败 - case ResultEnum.ERROR: - showFailToast(errorMsg) - break - // token 过期 - case ResultEnum.TOKEN_EXPIRED: - const LoginName = PageEnum.BASE_LOGIN_NAME - const LoginPath = PageEnum.BASE_LOGIN - if (router.currentRoute.value?.name === LoginName) { - return - } - // 到登录页 - errorMsg = '登录超时,请重新登录!' - showDialog({ - title: '提示', - message: '登录身份已失效,请重新登录!', - }) - .then(() => { - storage.clear() - window.location.href = LoginPath - }) - .catch(() => { - // on cancel - }) - break + // 请求失败 + console.log(code) + if (code) { + showFailToast(errorMsg) } throw new Error(errorMsg) }, diff --git a/src/views/daxpay/channel/ChannelAuth.api.ts b/src/views/daxpay/channel/ChannelAuth.api.ts index 02a07e7..00a6348 100644 --- a/src/views/daxpay/channel/ChannelAuth.api.ts +++ b/src/views/daxpay/channel/ChannelAuth.api.ts @@ -13,7 +13,6 @@ export function authAndSet(param: AuthCodeParam) { }) } - /** * 通道认证参数 */ @@ -27,3 +26,17 @@ export interface AuthCodeParam { // 应用号 appId?: string } + +/** + * AuthResult + */ +export interface AuthResult { + // OpenId + openId?: string + // 用户ID + userId?: string + // AccessToken + accessToken?: string + // 状态 + status?: string +} diff --git a/src/views/daxpay/channel/ChannelCashier.api.ts b/src/views/daxpay/channel/ChannelCashier.api.ts index eae49dd..f794d26 100644 --- a/src/views/daxpay/channel/ChannelCashier.api.ts +++ b/src/views/daxpay/channel/ChannelCashier.api.ts @@ -1,3 +1,4 @@ +import type { AuthResult } from './ChannelAuth.api' import { http } from '@/utils/http/axios' import type { Result } from '#/axios' @@ -26,9 +27,20 @@ export function getCashierInfo(cashierType: string, appId: string) { /** * 获取收银台所需授权链接, 用于获取OpenId一类的信息 */ -export function generateAuthUrl(param: CashierAuthCodeParam) { +export function generateAuthUrl(param: CashierAuthParam) { return http.request>({ - url: '/unipay/ext/channel/cashier/authCode', + url: '/unipay/ext/channel/cashier/generateAuthUrl', + method: 'POST', + data: param, + }) +} + +/** + * 获取授权信息 + */ +export function auth(param: CashierPayParam) { + return http.request>({ + url: '/unipay/ext/channel/cashier/auth', method: 'POST', data: param, }) @@ -48,13 +60,15 @@ export function cashierPay(param: CashierPayParam) { /** * 通道认证参数 */ -export interface CashierAuthCodeParam { +export interface CashierAuthParam { // 商户号 mchNo?: string // 应用号 appId?: string // 收银台类型 cashierType?: string + // 授权码 + authCode?: string } /** @@ -70,8 +84,8 @@ export interface CashierPayParam { cashierType?: string // 支付金额 amount?: number - // 标识码 - authCode?: string + // 唯一标识 + openId?: string // 支付描述 description?: string } diff --git a/src/views/daxpay/channel/ChannelCashier.vue b/src/views/daxpay/channel/ChannelCashier.vue index c99c4f0..08642f7 100644 --- a/src/views/daxpay/channel/ChannelCashier.vue +++ b/src/views/daxpay/channel/ChannelCashier.vue @@ -1,34 +1,19 @@ diff --git a/src/views/daxpay/channel/alipay/cashier/AlipayCashier.vue b/src/views/daxpay/channel/alipay/cashier/AlipayCashier.vue index 37771e3..3fd5400 100644 --- a/src/views/daxpay/channel/alipay/cashier/AlipayCashier.vue +++ b/src/views/daxpay/channel/alipay/cashier/AlipayCashier.vue @@ -14,7 +14,7 @@ @@ -57,6 +62,7 @@ diff --git a/src/views/daxpay/channel/wechat/cashier/WechatCashier.vue b/src/views/daxpay/channel/wechat/cashier/WechatCashier.vue index a7c0edb..f26e1bd 100644 --- a/src/views/daxpay/channel/wechat/cashier/WechatCashier.vue +++ b/src/views/daxpay/channel/wechat/cashier/WechatCashier.vue @@ -1,5 +1,5 @@