diff --git a/.env.development b/.env.development index a726e58..a794754 100644 --- a/.env.development +++ b/.env.development @@ -9,7 +9,7 @@ VITE_DROP_CONSOLE = false # 跨域代理,可以配置多个,请注意不要换行 # /server 代理到本地后端网关(端口 19999) -VITE_PROXY = [["/server","http://127.0.0.1:19999/"]] +VITE_PROXY = [["/server","http://127.0.0.1:9999/"]] # API 接口地址 # 如果没有跨域问题,直接在这里配置即可 diff --git a/README.md b/README.md index a8fcd76..36febe1 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,11 @@ pnpm run lint:fix ## 环境配置 -| 文件 | 说明 | -| ------------------ | -------------------------------------------------------------------- | -| `.env` | 应用基础信息(标题、端口) | -| `.env.development` | 开发环境(代理 `/server` → `http://127.0.0.1:19999`、vconsole 开启) | -| `.env.production` | 生产环境(接口前缀、压缩配置) | +| 文件 | 说明 | +| ------------------ | ------------------------------------------------------------------- | +| `.env` | 应用基础信息(标题、端口) | +| `.env.development` | 开发环境(代理 `/server` → `http://127.0.0.1:9999`、vconsole 开启) | +| `.env.production` | 生产环境(接口前缀、压缩配置) | ## License diff --git a/src/mobile/router/modules.ts b/src/mobile/router/modules.ts index cee8fba..86301fe 100644 --- a/src/mobile/router/modules.ts +++ b/src/mobile/router/modules.ts @@ -75,6 +75,15 @@ const routeModuleList: Array = [ }, ], }, + // 支付宝认证落地页(移动独占:支付宝 App 内 JSAPI 取码) + { + path: RoutePath.AUTH_ALIPAY, + name: 'AlipayAuth', + component: () => import('@/mobile/views/auth/alipay/index.vue'), + meta: { + title: '支付宝认证', + }, + }, ] export default routeModuleList diff --git a/src/mobile/views/auth/alipay/index.vue b/src/mobile/views/auth/alipay/index.vue new file mode 100644 index 0000000..ffaa587 --- /dev/null +++ b/src/mobile/views/auth/alipay/index.vue @@ -0,0 +1,326 @@ + + + + + diff --git a/src/shared/api/channel-auth.ts b/src/shared/api/channel-auth.ts new file mode 100644 index 0000000..4b9a246 --- /dev/null +++ b/src/shared/api/channel-auth.ts @@ -0,0 +1,43 @@ +import { RequestEnum } from '@/shared/enums/httpEnum' +import { http } from '@/shared/utils/http/axios' + +/** + * 通过 AuthCode 获取认证结果(H5 落地页回写) + */ +export function authAndGet(param: AuthCodeParam): Promise { + return http.request({ + url: '/unipay/assist/channel/auth/auth', + method: RequestEnum.POST, + data: param, + }, { + // 由页面自行处理错误展示 + isShowMessage: false, + }) +} + +/** 通道认证参数 */ +export interface AuthCodeParam { + /** 认证类型 alipay/wechat/... */ + authType?: string + /** 授权码 */ + authCode?: string + /** 查询码(管理端轮询用) */ + queryCode?: string + /** 通道 */ + channel?: string + /** 应用号 */ + appId?: string + /** 认证会话码 */ + authToken?: string + /** 支付产品 */ + product?: string +} + +/** 认证结果 */ +export interface AuthResult { + openId?: string + userId?: string + accessToken?: string + status?: string + returnPath?: string +} diff --git a/src/shared/locales/en-US/auth.json b/src/shared/locales/en-US/auth.json new file mode 100644 index 0000000..f7d3ffd --- /dev/null +++ b/src/shared/locales/en-US/auth.json @@ -0,0 +1,17 @@ +{ + "alipay": { + "loading": "Fetching authorization...", + "secureTip": "Alipay secure auth", + "successTitle": "Success", + "failTitle": "Failed", + "userId": "Alipay User ID", + "copy": "Copy", + "close": "Close", + "copySuccess": "Copied", + "copyFail": "Copy failed", + "sdkLoadFail": "Failed to load Alipay SDK. Open in Alipay app.", + "paramMissing": "Missing auth parameters", + "authCodeFail": "Failed to get auth code", + "authFail": "Failed to get user id" + } +} diff --git a/src/shared/locales/en-US/index.ts b/src/shared/locales/en-US/index.ts index ad6b3c9..d75d566 100644 --- a/src/shared/locales/en-US/index.ts +++ b/src/shared/locales/en-US/index.ts @@ -1,3 +1,4 @@ +import auth from './auth.json' import cashier from './cashier.json' import codePay from './codePay.json' import common from './common.json' @@ -10,6 +11,7 @@ import statement from './statement.json' export default { common, http, + auth, cashier, codePay, protocol, diff --git a/src/shared/locales/zh-CN/auth.json b/src/shared/locales/zh-CN/auth.json new file mode 100644 index 0000000..ad0207f --- /dev/null +++ b/src/shared/locales/zh-CN/auth.json @@ -0,0 +1,17 @@ +{ + "alipay": { + "loading": "正在获取授权信息...", + "secureTip": "支付宝安全认证", + "successTitle": "获取成功", + "failTitle": "获取失败", + "userId": "支付宝用户ID", + "copy": "复制信息", + "close": "关闭页面", + "copySuccess": "复制成功", + "copyFail": "复制失败", + "sdkLoadFail": "支付宝 SDK 加载失败,请在支付宝内打开", + "paramMissing": "授权参数缺失", + "authCodeFail": "获取授权码失败", + "authFail": "获取用户标识失败" + } +} diff --git a/src/shared/locales/zh-CN/index.ts b/src/shared/locales/zh-CN/index.ts index ad6b3c9..d75d566 100644 --- a/src/shared/locales/zh-CN/index.ts +++ b/src/shared/locales/zh-CN/index.ts @@ -1,3 +1,4 @@ +import auth from './auth.json' import cashier from './cashier.json' import codePay from './codePay.json' import common from './common.json' @@ -10,6 +11,7 @@ import statement from './statement.json' export default { common, http, + auth, cashier, codePay, protocol, diff --git a/src/shared/router/exclusive.ts b/src/shared/router/exclusive.ts index 4c77cf6..3c4da25 100644 --- a/src/shared/router/exclusive.ts +++ b/src/shared/router/exclusive.ts @@ -27,6 +27,8 @@ export interface ExclusiveRoute { export const EXCLUSIVE_ROUTES: ExclusiveRoute[] = [ // 码牌支付:仅移动端实现 { path: RoutePath.CODE_PAY, name: 'CodePay', device: 'mobile' }, + // 支付宝认证落地页:仅移动端实现(支付宝 App 内 JSAPI) + { path: RoutePath.AUTH_ALIPAY, name: 'AlipayAuth', device: 'mobile' }, // 商户对账单:仅 PC 端实现 { path: RoutePath.MERCHANT_STATEMENT, name: 'MerchantStatement', device: 'pc' }, ] diff --git a/src/shared/router/paths.ts b/src/shared/router/paths.ts index 7927ada..c6da301 100644 --- a/src/shared/router/paths.ts +++ b/src/shared/router/paths.ts @@ -23,4 +23,6 @@ export const RoutePath = { MERCHANT_STATEMENT: '/merchant/statement', /** 协议展示页(跨端:用户协议/隐私政策,链接可独立分享) */ PROTOCOL: '/protocol/:protocolType', + /** 支付宝认证落地页(移动独占:JSAPI 取码) */ + AUTH_ALIPAY: '/auth/alipay/:aliAppId/:queryCode', } as const diff --git a/vite.config.ts b/vite.config.ts index 520053a..98513df 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -142,6 +142,8 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { open: false, // 服务端口号 port: Number(VITE_PORT), + // 允许 nginx 反代的自定义域名访问(抖音 OAuth 本地调试) + allowedHosts: true, proxy: createProxy(VITE_PROXY), // 预热文件以降低启动期间的初始页面加载时长 warmup: {