From b6927ffe1ea8b08ae52d295476f9123ef6b09e5a Mon Sep 17 00:00:00 2001 From: DaxPay Dev Date: Thu, 9 Jul 2026 17:08:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor(social):=20=E6=94=AF=E4=BB=98=E5=AE=9D?= =?UTF-8?q?=E7=99=BB=E5=BD=95/=E7=BB=91=E5=AE=9A=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E8=B5=B0=20SocialApi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去掉 AlipayAuthApi 与 renderSocialAuth 特判,回调页仅归一 auth_code/code。 Co-authored-by: Cursor --- apps/daxpay-admin/src/api/iam/social.api.ts | 50 ------------------- .../components/AuthThirdPartyPanel.vue | 7 ++- .../_core/authentication/oauth-callback.vue | 10 ++-- .../authentication/social-bind-callback.vue | 9 ++-- .../src/views/profile/social-bind.vue | 5 +- 5 files changed, 11 insertions(+), 70 deletions(-) diff --git a/apps/daxpay-admin/src/api/iam/social.api.ts b/apps/daxpay-admin/src/api/iam/social.api.ts index 6d6eeb828..3212b5c6d 100644 --- a/apps/daxpay-admin/src/api/iam/social.api.ts +++ b/apps/daxpay-admin/src/api/iam/social.api.ts @@ -173,53 +173,3 @@ export interface SocialEnabledPlatform { /** 平台编码(weChat/weCom/qq/github/gitee/feishu/dingTalk/douyin/alipay) */ source: string; } - -/** - * 支付宝授权登录专用 API - * - * 支付宝非标准 OAuth2(走 alipay.system.oauth.token), 不复用 JustAuth 的 SocialApi.render/exchangeLogin, - * 使用独立的 render/exchange 端点。配置走平台级 PlatformAlipayAuthConfigApi。 - */ -export const AlipayAuthApi = { - /** - * 生成支付宝授权地址(前端拿到后 location.href 跳转) - * @param client 终端编码(admin/merchant) - * @param mode 授权场景: BIND(已登录绑定) | LOGIN(未登录登录), 不传按登录态判断 - */ - render(client: string = 'admin', mode?: string): Promise> { - return defHttp.get({ url: '/social/alipay/render', params: { client, mode } }); - }, - - /** - * 支付宝授权码兑换(LOGIN/BIND 由 mode 决定) - * @param authCode 支付宝回调回传的 auth_code - * @param state render 阶段生成的 state - * @param client 终端编码 - * @param mode 授权场景 - */ - exchange( - authCode: string, - state: string, - client: string = 'admin', - mode?: string, - ): Promise> { - return defHttp.post({ - url: '/social/alipay/exchange', - params: { authCode, state, client, mode }, - }); - }, -}; - -/** - * 统一生成三方授权地址 - * 支付宝走专用端点, 其余走 JustAuth 标准 render - */ -export function renderSocialAuth( - source: string, - client: string = 'admin', - mode?: string, -): Promise> { - return source === 'alipay' - ? AlipayAuthApi.render(client, mode) - : SocialApi.render(source, client, mode); -} diff --git a/apps/daxpay-admin/src/views/_core/authentication/components/AuthThirdPartyPanel.vue b/apps/daxpay-admin/src/views/_core/authentication/components/AuthThirdPartyPanel.vue index b5119c94c..4a28c1692 100644 --- a/apps/daxpay-admin/src/views/_core/authentication/components/AuthThirdPartyPanel.vue +++ b/apps/daxpay-admin/src/views/_core/authentication/components/AuthThirdPartyPanel.vue @@ -3,7 +3,7 @@ import { $t } from '@vben/locales'; - import { renderSocialAuth, SocialApi } from '#/api/iam/social.api'; + import { SocialApi } from '#/api/iam/social.api'; import { SocialLogo } from '#/components/social'; defineOptions({ name: 'AuthThirdPartyPanel' }); @@ -35,8 +35,7 @@ } /** - * 点击三方图标, 获取授权地址并跳转 - * 支付宝走专用端点(非标准 OAuth2), 其余走 JustAuth 标准 render + * 点击三方图标, 获取授权地址并跳转(含支付宝, 统一走 SocialApi.render) */ async function handleSocialLogin(source: string) { // 仅登录场景校验协议勾选,提示由父表单红字显示(绑定场景不校验) @@ -44,7 +43,7 @@ const ok = await props.ensureAgreement(); if (!ok) return; } - const { data: url } = await renderSocialAuth(source, 'admin', props.mode); + const { data: url } = await SocialApi.render(source, 'admin', props.mode); if (url) { // 跳转到第三方授权页, 授权后由后端回调处理并重定向回前端 /oauth-callback window.location.href = url; diff --git a/apps/daxpay-admin/src/views/_core/authentication/oauth-callback.vue b/apps/daxpay-admin/src/views/_core/authentication/oauth-callback.vue index e31b31b3b..47580bf33 100644 --- a/apps/daxpay-admin/src/views/_core/authentication/oauth-callback.vue +++ b/apps/daxpay-admin/src/views/_core/authentication/oauth-callback.vue @@ -5,7 +5,7 @@ import { $t } from '@vben/locales'; import { useAccessStore } from '@vben/stores'; - import { AlipayAuthApi, SocialApi } from '#/api/iam/social.api'; + import { SocialApi } from '#/api/iam/social.api'; import { SocialLogo } from '#/components/social'; import { useMessage } from '#/hooks/useMessage'; import { HOME_PATH } from '#/router/routes'; @@ -42,8 +42,7 @@ /** * 处理社交登录回调(仅登录场景) - * 标准平台: URL 含 code+state → SocialApi.exchangeLogin - * 支付宝: URL 含 auth_code+state → AlipayAuthApi.exchange(兼容 code) + * 支付宝回传 auth_code, 标准 OAuth 回传 code; 归一后统一走 SocialApi.exchangeLogin */ onMounted(async () => { const { code, auth_code: authCode, state } = route.query; @@ -55,10 +54,7 @@ return; } try { - const res = - source.value === 'alipay' - ? await AlipayAuthApi.exchange(oauthCode, state as string, 'admin', 'LOGIN') - : await SocialApi.exchangeLogin(oauthCode, state as string, source.value, 'admin'); + const res = await SocialApi.exchangeLogin(oauthCode, state as string, source.value, 'admin'); await handleResult(res.data?.token, res.data?.error); } catch { message.error($t('_core.authentication.oauthProcessFailed')); diff --git a/apps/daxpay-admin/src/views/_core/authentication/social-bind-callback.vue b/apps/daxpay-admin/src/views/_core/authentication/social-bind-callback.vue index eb615c18c..c0aeebd00 100644 --- a/apps/daxpay-admin/src/views/_core/authentication/social-bind-callback.vue +++ b/apps/daxpay-admin/src/views/_core/authentication/social-bind-callback.vue @@ -4,7 +4,7 @@ import { $t } from '@vben/locales'; - import { AlipayAuthApi, SocialApi } from '#/api/iam/social.api'; + import { SocialApi } from '#/api/iam/social.api'; defineOptions({ name: 'SocialBindCallback' }); @@ -33,7 +33,7 @@ /** * 处理绑定回调: 用授权码+state 调后端兑换, 成功后通知父窗口并关闭弹窗 - * 支付宝回传 auth_code, 标准 OAuth 回传 code + * 支付宝回传 auth_code, 标准 OAuth 回传 code; 归一后统一走 SocialApi.exchangeBind */ onMounted(async () => { const { code, auth_code: authCode, state } = route.query; @@ -44,10 +44,7 @@ return; } try { - const res = - source.value === 'alipay' - ? await AlipayAuthApi.exchange(oauthCode, state as string, 'admin', 'BIND') - : await SocialApi.exchangeBind(oauthCode, state as string, source.value, 'admin'); + const res = await SocialApi.exchangeBind(oauthCode, state as string, source.value, 'admin'); if (res.data?.result === 'bind_success') { success.value = true; loading.value = false; diff --git a/apps/daxpay-admin/src/views/profile/social-bind.vue b/apps/daxpay-admin/src/views/profile/social-bind.vue index d93514570..9074eca6f 100644 --- a/apps/daxpay-admin/src/views/profile/social-bind.vue +++ b/apps/daxpay-admin/src/views/profile/social-bind.vue @@ -5,7 +5,7 @@ import { $t } from '@vben/locales'; - import { renderSocialAuth, SocialApi } from '#/api/iam/social.api'; + import { SocialApi } from '#/api/iam/social.api'; import { SocialLogo } from '#/components/social'; import { useMessage } from '#/hooks/useMessage'; @@ -47,10 +47,9 @@ /** * 绑定第三方账号(打开弹窗进行授权, 授权后弹窗自动关闭并通知刷新) - * 支付宝走专用端点, 与登录页 renderSocialAuth 一致 */ async function handleBind(source: string) { - const { data: url } = await renderSocialAuth(source, 'admin', 'BIND'); + const { data: url } = await SocialApi.render(source, 'admin', 'BIND'); if (url) { window.open(url, 'social-bind', 'width=600,height=700'); }