环境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

View File

@ -118,7 +118,13 @@ Page({
app.imLogout(); app.imLogout();
url = "/Pages/yaoshi/home/home"; url = "/Pages/yaoshi/home/home";
} }
let token = wx.getStorageSync('AUTH_TOKEN_'+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)
}
console.log(token); console.log(token);
console.log(url); console.log(url);
if(token){ if(token){

View File

@ -35,7 +35,14 @@ Page({
success (res) { success (res) {
if (res.confirm) { if (res.confirm) {
console.log('用户点击确定') console.log('用户点击确定')
wx.setStorageSync('AUTH_TOKEN_'+usertype, ""); //wx.setStorageSync('AUTH_TOKEN_'+usertype, "");
const { envVersion } = wx.getAccountInfoSync().miniProgram;
if(envVersion=='release'){
wx.setStorageSync('AUTH_TOKEN_'+usertype, '');
}else{
wx.setStorageSync('DEV_AUTH_TOKEN_'+usertype,'');
}
wx.setStorageSync('user_id_'+usertype, ""); wx.setStorageSync('user_id_'+usertype, "");
wx.setStorageSync('client_user_id_'+usertype, ""); wx.setStorageSync('client_user_id_'+usertype, "");
app.globalData.isLogin=false; app.globalData.isLogin=false;

View File

@ -87,7 +87,8 @@
</view> </view>
<view class="content_4" wx:if="{{ item.inquiry_status == 3 }}"> <view class="content_4" wx:if="{{ item.inquiry_status == 3 }}">
<text wx:if="{{item.inquiry_type ==2 || item.inquiry_type ==4}}">不接诊5分钟后自动取消</text> <text wx:if="{{item.inquiry_type ==2 || item.inquiry_type ==4}}">不接诊5分钟后自动取消</text>
<text wx:elif="{{item.inquiry_type ==3 || item.inquiry_type ==1}}">不接诊24小时后自动取消</text> <text wx:elif="{{item.inquiry_type ==3 || (item.inquiry_type ==1 && item.inquiry_mode!=8 && item.inquiry_mode!=9)}}">不接诊24小时后自动取消</text>
<text wx:elif="{{item.inquiry_type ==1 && (item.inquiry_mode==8 || item.inquiry_mode==9)}}">不接诊72小时后自动取消</text>
</view> </view>
</view> </view>
<!-- aa --> <!-- aa -->

9
app.js
View File

@ -49,6 +49,7 @@ App({
if(userID == ""){ if(userID == ""){
return; return;
} }
this.globalData.config.userID = userID; this.globalData.config.userID = userID;
// let sign = genTestUserSig(this.globalData.config); // let sign = genTestUserSig(this.globalData.config);
// console.log("sign: ", sign); // console.log("sign: ", sign);
@ -170,7 +171,13 @@ App({
onKickedOut(){ onKickedOut(){
// console.log("onKickedOutonKickedOutonKickedOutonKickedOut"); // console.log("onKickedOutonKickedOutonKickedOutonKickedOut");
let usertype = wx.getStorageSync('usertype'); let usertype = wx.getStorageSync('usertype');
wx.setStorageSync('AUTH_TOKEN_'+usertype, ""); // wx.setStorageSync('AUTH_TOKEN_'+usertype, "");
const { envVersion } = wx.getAccountInfoSync().miniProgram;
if(envVersion=='release'){
wx.setStorageSync('AUTH_TOKEN_'+usertype, '');
}else{
wx.setStorageSync('DEV_AUTH_TOKEN_'+usertype, '');
}
wx.setStorageSync('user_id_'+usertype, ""); wx.setStorageSync('user_id_'+usertype, "");
wx.setStorageSync('client_user_id_'+usertype, ""); wx.setStorageSync('client_user_id_'+usertype, "");
if(wx.$TUIKit){ if(wx.$TUIKit){

View File

@ -145,8 +145,15 @@ Page({
wx_code: res.code wx_code: res.code
} }
api.wechatMobileLogin(params).then(response => { api.wechatMobileLogin(params).then(response => {
console.log(response); // console.log(response);
wx.setStorageSync('AUTH_TOKEN_'+usertype, response.data.token); const { envVersion } = wx.getAccountInfoSync().miniProgram;
if(envVersion=='release'){
wx.setStorageSync('AUTH_TOKEN_'+usertype, response.data.token);
}else{
wx.setStorageSync('DEV_AUTH_TOKEN_'+usertype, response.data.token);
}
wx.setStorageSync('user_id_'+usertype, response.data.user_id); wx.setStorageSync('user_id_'+usertype, response.data.user_id);
wx.setStorageSync('client_user_id_'+usertype, response.data.client_user_id); wx.setStorageSync('client_user_id_'+usertype, response.data.client_user_id);
app.globalData.config.userID = response.data.user_id; app.globalData.config.userID = response.data.user_id;

View File

@ -138,8 +138,14 @@ Page({
api.mobileLogin(params).then(response => { api.mobileLogin(params).then(response => {
app.globalData.isLogin=true; app.globalData.isLogin=true;
console.log(response); const { envVersion } = wx.getAccountInfoSync().miniProgram;
wx.setStorageSync('AUTH_TOKEN_'+usertype, response.data.token); if(envVersion=='release'){
wx.setStorageSync('AUTH_TOKEN_'+usertype, response.data.token);
}else{
wx.setStorageSync('DEV_AUTH_TOKEN_'+usertype, response.data.token);
}
// wx.setStorageSync('AUTH_TOKEN_'+usertype, response.data.token);
wx.setStorageSync('user_id_'+usertype, response.data.user_id); wx.setStorageSync('user_id_'+usertype, response.data.user_id);
wx.setStorageSync('client_user_id_'+usertype, response.data.client_user_id); wx.setStorageSync('client_user_id_'+usertype, response.data.client_user_id);
app.globalData.config.userID = response.data.user_id; app.globalData.config.userID = response.data.user_id;

View File

@ -35,7 +35,13 @@ Page({
success (res) { success (res) {
if (res.confirm) { if (res.confirm) {
console.log('用户点击确定') console.log('用户点击确定')
wx.setStorageSync('AUTH_TOKEN_'+usertype, ""); const { envVersion } = wx.getAccountInfoSync().miniProgram;
if(envVersion=='release'){
wx.setStorageSync('AUTH_TOKEN_'+usertype, '');
}else{
wx.setStorageSync('DEV_AUTH_TOKEN_'+usertype, '');
}
// wx.setStorageSync('AUTH_TOKEN_'+usertype, "");
wx.setStorageSync('user_id_'+usertype, ""); wx.setStorageSync('user_id_'+usertype, "");
wx.setStorageSync('client_user_id_'+usertype, ""); wx.setStorageSync('client_user_id_'+usertype, "");
app.globalData.isLogin=false; app.globalData.isLogin=false;

View File

@ -51,7 +51,13 @@ Page({
if (res.confirm) { if (res.confirm) {
console.log('用户点击确定') console.log('用户点击确定')
let usertype = wx.getStorageSync('usertype'); let usertype = wx.getStorageSync('usertype');
wx.setStorageSync('AUTH_TOKEN_'+usertype, ""); const { envVersion } = wx.getAccountInfoSync().miniProgram;
if(envVersion=='release'){
wx.setStorageSync('AUTH_TOKEN_'+usertype, '');
}else{
wx.setStorageSync('DEV_AUTH_TOKEN_'+usertype, '');
}
// wx.setStorageSync('AUTH_TOKEN_'+usertype, "");
wx.setStorageSync('user_id_'+usertype, ""); wx.setStorageSync('user_id_'+usertype, "");
wx.setStorageSync('client_user_id_'+usertype, ""); wx.setStorageSync('client_user_id_'+usertype, "");

View File

@ -28,19 +28,32 @@ class HTTP {
_request(url, resolve, reject, data = {}, method = 'GET', contentType = 'application/json', showLoading = true) { _request(url, resolve, reject, data = {}, method = 'GET', contentType = 'application/json', showLoading = true) {
if(showLoading) wx.showLoading(); if(showLoading) wx.showLoading();
let usertype = wx.getStorageSync('usertype'); 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({ wx.request({
url: url, url: url,
method: method, method: method,
data: data, data: data,
header: { header: {
'content-type': contentType, 'content-type': contentType,
'Authorization': "Bearer " + wx.getStorageSync('AUTH_TOKEN_'+usertype) 'Authorization': "Bearer " + token
}, },
success: (res) => { success: (res) => {
// console.log("header Authorization: ", res.header.Authorization); // console.log("header Authorization: ", res.header.Authorization);
var Authorization_token = res.header.Authorization; var Authorization_token = res.header.Authorization;
if(Authorization_token){ 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) { if (res.data) {
const code = res.data.code; const code = res.data.code;