From d52e10b09ea9ff310c5e987c0bcb5031e9e2ef65 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Wed, 9 Sep 2026 12:20:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BE=AE=E4=BF=A1=20OAuth=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=94=B9=E7=94=A8=20fetch=20=E9=81=BF=E5=85=8D=20OPTI?= =?UTF-8?q?ONS=20405?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- src/api/wechat/index.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/api/wechat/index.ts b/src/api/wechat/index.ts index c8fdf88..44943f6 100644 --- a/src/api/wechat/index.ts +++ b/src/api/wechat/index.ts @@ -9,6 +9,7 @@ import type { WxFollowQrcodeResult, WxLoginQrcodeResult, WxLoginResult, + WxLoginStatusResult, WxOAuthConfigResult, } from './types'; @@ -48,11 +49,14 @@ export async function getFollowQrcode(): Promise { /** H5 网页授权:从其他配置 wechat_mp 读取 AppId / OAuth 回调根 */ export async function getWeChatOAuthConfig(): Promise { - // 不带默认 Content-Type,避免无必要的 CORS 预检(OPTIONS 易被网关/路由判 405) - const res = await axiosInstance.get(omsUrl('/wechat/oauth/config'), { - headers: { 'Content-Type': undefined as unknown as string }, - }); - const data = unwrapOrSelf>(res.data); + // 用 fetch 发简单 GET,避免 axios 默认 Content-Type 触发 OPTIONS(易 405) + const url = omsUrl('/wechat/oauth/config'); + const res = await fetch(url, { method: 'GET' }); + if (!res.ok) { + throw new Error(`获取微信 OAuth 配置失败(${res.status})`); + } + const body = await res.json(); + const data = unwrapOrSelf>(body); const appId = String(data.appId ?? data.AppId ?? '').trim(); const oauthRedirectBase = String( data.oauthRedirectBase ?? data.OAuthRedirectBase ?? '',