修改接口授权失败重新登录
This commit is contained in:
+19
-3
@@ -3,7 +3,7 @@ import config from './config';
|
|||||||
|
|
||||||
// 微信配置
|
// 微信配置
|
||||||
const WECHAT_CONFIG = {
|
const WECHAT_CONFIG = {
|
||||||
appId: '', // 需要配置你的微信公众号AppID
|
appId: 'wx10561f0e5ea2951f', // 需要配置你的微信公众号AppID
|
||||||
scope: {
|
scope: {
|
||||||
BASE: 'snsapi_base', // 静默授权,获取openid
|
BASE: 'snsapi_base', // 静默授权,获取openid
|
||||||
USERINFO: 'snsapi_userinfo' // 用户授权,获取用户信息
|
USERINFO: 'snsapi_userinfo' // 用户授权,获取用户信息
|
||||||
@@ -139,6 +139,7 @@ const WechatAuth = {
|
|||||||
|
|
||||||
// 重新发起授权
|
// 重新发起授权
|
||||||
const currentUrl = window.location.href.split('?')[0].split('#')[0];
|
const currentUrl = window.location.href.split('?')[0].split('#')[0];
|
||||||
|
console.log("配置信息:",WECHAT_CONFIG);
|
||||||
this.authorize(currentUrl);
|
this.authorize(currentUrl);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -169,8 +170,23 @@ service.interceptors.request.use(
|
|||||||
let isAuthing = false; // 授权标记位
|
let isAuthing = false; // 授权标记位
|
||||||
|
|
||||||
service.interceptors.response.use(
|
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;
|
return response.data;
|
||||||
},
|
},
|
||||||
async (error) => {
|
async (error) => {
|
||||||
@@ -227,7 +243,7 @@ const wechatAPI = {
|
|||||||
if (friend_account_id) {
|
if (friend_account_id) {
|
||||||
params.friend_account_id = friend_account_id;
|
params.friend_account_id = friend_account_id;
|
||||||
}
|
}
|
||||||
return service.get('/auto/login', params);
|
return service.post('/auto/login', params);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user