环境token

This commit is contained in:
zoujiandong
2024-05-07 10:37:12 +08:00
parent 5130ea5c7a
commit 28d49809e6
9 changed files with 71 additions and 12 deletions
+15 -2
View File
@@ -28,19 +28,32 @@ class HTTP {
_request(url, resolve, reject, data = {}, method = 'GET', contentType = 'application/json', showLoading = true) {
if(showLoading) wx.showLoading();
let usertype = wx.getStorageSync('usertype');
let token='';
const { envVersion } = wx.getAccountInfoSync().miniProgram;
if(envVersion=='release'){
token= wx.getStorageSync('AUTH_TOKEN_'+usertype)
}else{
token= wx.getStorageSync('DEV_AUTH_TOKEN_'+usertype)
}
wx.request({
url: url,
method: method,
data: data,
header: {
'content-type': contentType,
'Authorization': "Bearer " + wx.getStorageSync('AUTH_TOKEN_'+usertype)
'Authorization': "Bearer " + token
},
success: (res) => {
// console.log("header Authorization: ", res.header.Authorization);
var Authorization_token = res.header.Authorization;
if(Authorization_token){
wx.setStorageSync('AUTH_TOKEN_'+usertype, Authorization_token);//当token快过期时,服务器会返回新token,本地刷新
const { envVersion } = wx.getAccountInfoSync().miniProgram;
if(envVersion=='release'){
wx.setStorageSync('AUTH_TOKEN_'+usertype, Authorization_token);//当token快过期时,服务器会返回新token,本地刷新
}else{
wx.setStorageSync('DEV_AUTH_TOKEN_'+usertype, Authorization_token);//当token快过期时,服务器会返回新token,本地刷新
}
}
if (res.data) {
const code = res.data.code;