fix: 微信 OAuth 配置改用 fetch 避免 OPTIONS 405
All checks were successful
Build and Deploy Front / deploy (push) Successful in 9m16s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-09-09 12:20:26 +08:00
parent 6788de9016
commit d52e10b09e

View File

@ -9,6 +9,7 @@ import type {
WxFollowQrcodeResult, WxFollowQrcodeResult,
WxLoginQrcodeResult, WxLoginQrcodeResult,
WxLoginResult, WxLoginResult,
WxLoginStatusResult,
WxOAuthConfigResult, WxOAuthConfigResult,
} from './types'; } from './types';
@ -48,11 +49,14 @@ export async function getFollowQrcode(): Promise<WxFollowQrcodeResult> {
/** H5 网页授权:从其他配置 wechat_mp 读取 AppId / OAuth 回调根 */ /** H5 网页授权:从其他配置 wechat_mp 读取 AppId / OAuth 回调根 */
export async function getWeChatOAuthConfig(): Promise<WxOAuthConfigResult> { export async function getWeChatOAuthConfig(): Promise<WxOAuthConfigResult> {
// 不带默认 Content-Type,避免无必要的 CORS 预检(OPTIONS 易被网关/路由判 405) // 用 fetch 发简单 GET,避免 axios 默认 Content-Type 触发 OPTIONS(易 405)
const res = await axiosInstance.get(omsUrl('/wechat/oauth/config'), { const url = omsUrl('/wechat/oauth/config');
headers: { 'Content-Type': undefined as unknown as string }, const res = await fetch(url, { method: 'GET' });
}); if (!res.ok) {
const data = unwrapOrSelf<WxOAuthConfigResult & Record<string, unknown>>(res.data); throw new Error(`获取微信 OAuth 配置失败(${res.status})`);
}
const body = await res.json();
const data = unwrapOrSelf<WxOAuthConfigResult & Record<string, unknown>>(body);
const appId = String(data.appId ?? data.AppId ?? '').trim(); const appId = String(data.appId ?? data.AppId ?? '').trim();
const oauthRedirectBase = String( const oauthRedirectBase = String(
data.oauthRedirectBase ?? data.OAuthRedirectBase ?? '', data.oauthRedirectBase ?? data.OAuthRedirectBase ?? '',