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 ?? '',