From d14dd9fef958034a88086b98b7f30f2f7cf0f397 Mon Sep 17 00:00:00 2001 From: lcc <805383944@qq.com> Date: Sun, 12 Oct 2025 14:48:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E5=A4=B1=E8=B4=A5=E9=87=8D=E6=96=B0=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/api.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/utils/api.js b/src/utils/api.js index e6913f1..135cd84 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -3,7 +3,7 @@ import config from './config'; // 微信配置 const WECHAT_CONFIG = { - appId: '', // 需要配置你的微信公众号AppID + appId: 'wx10561f0e5ea2951f', // 需要配置你的微信公众号AppID scope: { BASE: 'snsapi_base', // 静默授权,获取openid USERINFO: 'snsapi_userinfo' // 用户授权,获取用户信息 @@ -139,6 +139,7 @@ const WechatAuth = { // 重新发起授权 const currentUrl = window.location.href.split('?')[0].split('#')[0]; + console.log("配置信息:",WECHAT_CONFIG); this.authorize(currentUrl); } }; @@ -169,8 +170,23 @@ service.interceptors.request.use( let isAuthing = false; // 授权标记位 service.interceptors.response.use( - (response) => { + (response) => { // 直接返回响应数据(根据后端接口规范调整) + // console.log(response.data.code); + if (response.data.code === 403) { + // 如果在微信浏览器中,自动重新授权 + if (WechatAuth.isWechatBrowser() && !isAuthing) { + localStorage.removeItem("token"); + const urlParams = new URLSearchParams(window.location.search); + const friend_account_id = urlParams.get('friend_account_id'); + const accountId = urlParams.get('accountId'); + wechatAPI.checkAndLogin(window.location.href, accountId ? accountId : undefined,friend_account_id ? friend_account_id : undefined); + if(localStorage.getItem("token")){ + window.location.reload(); + } + // return Promise.reject(new Error('正在重新授权,请稍候...')); + } + } return response.data; }, async (error) => { @@ -227,7 +243,7 @@ const wechatAPI = { if (friend_account_id) { params.friend_account_id = friend_account_id; } - return service.get('/auto/login', params); + return service.post('/auto/login', params); }, /**