环境token
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user