From 9f62a856ba2a0f9c44799db0e9e12ca92c8226d9 Mon Sep 17 00:00:00 2001 From: wuxw <928255095@qq.com> Date: Thu, 18 Jan 2024 11:24:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B0=8F=E5=8C=BA=E6=88=90?= =?UTF-8?q?=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/java110/java110Request.js | 85 +++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/lib/java110/java110Request.js b/lib/java110/java110Request.js index 4516cfb..88c9a18 100644 --- a/lib/java110/java110Request.js +++ b/lib/java110/java110Request.js @@ -2,20 +2,33 @@ import coreUtil from './utils/CoreUtil.js' import app from '../../constant/AppConstant.js' -import {getDateYYYYMMDDHHMISS} from './utils/DateUtil.js' +import { + getDateYYYYMMDDHHMISS +} from './utils/DateUtil.js' import url from '../../constant/url.js' import mapping from '../../constant/MappingConstant.js' -import {checkSession} from './page/Page.js' +import { + checkSession +} from './page/Page.js' -import {getToken} from './utils/StorageUtil.js'; +import { + getToken +} from './utils/StorageUtil.js'; -import {hasLogin} from '../../api/user/sessionApi.js'; +import { + hasLogin +} from '../../api/user/sessionApi.js'; -import {debug,warn,info,error} from './utils/LogUtil.js'; +import { + debug, + warn, + info, + error +} from './utils/LogUtil.js'; import md5 from './utils/md5Util.js' /** * 获取请求头信息 @@ -24,7 +37,7 @@ import md5 from './utils/md5Util.js' export function getHeaders() { let _wAppId = uni.getStorageSync(mapping.W_APP_ID); let _token = getToken(); - if(!_token){ + if (!_token) { _token = "no login"; } return { @@ -36,47 +49,51 @@ export function getHeaders() { //"cookie": '_java110_token_=' + getToken(), "Accept": '*/*', "w-app-id": _wAppId, - "Authorization":"Bearer "+_token + "Authorization": "Bearer " + _token }; } -export function createSign(_reqObj){ - +export function createSign(_reqObj) { + let _header = _reqObj.header; let _transactionId = _header["transaction-id"]; let _reqTime = _header["req-time"]; let _appId = _header["app-id"]; - let reqInfo = _transactionId+_reqTime+_appId; - - if(_reqObj.method == 'GET'){ + let reqInfo = _transactionId + _reqTime + _appId; + + if (_reqObj.method == 'GET') { reqInfo += '?'; for (let key in _reqObj.data) { - if(_reqObj.data[key]){ - reqInfo += (key+'='+_reqObj.data[key]+'&'); - }else{ - reqInfo += (key+'='+'&'); + if (_reqObj.data[key]) { + reqInfo += (key + '=' + _reqObj.data[key] + '&'); + } else { + reqInfo += (key + '=' + '&'); } - + } - if(reqInfo.endsWith('&')){ - reqInfo = reqInfo.substr(0,reqInfo.length-1); + if (reqInfo.endsWith('&')) { + reqInfo = reqInfo.substr(0, reqInfo.length - 1); + } + } else { + if (typeof _reqObj.data === "object") { + reqInfo += JSON.stringify(_reqObj.data); + } else { + reqInfo += _reqObj.data; } - }else{ - reqInfo += JSON.stringify(_reqObj.data); } reqInfo += "whoisyoudad!!!" let _sign = md5(reqInfo); _reqObj.header.sign = _sign; - + } /** * http 请求 加入是否登录判断 */ export function request(_reqObj) { - - debug('java110Request','request',_reqObj); - + + debug('java110Request', 'request', _reqObj); + //这里判断只有在 post 方式时 放加载框 if (_reqObj.hasOwnProperty("method") && "POST" == _reqObj.method) { uni.showLoading({ @@ -106,18 +123,18 @@ export function request(_reqObj) { uni.request(_reqObj); return; } - - if(!hasLogin()){ + + if (!hasLogin()) { //todo 这里延迟跳转,等待如果界面又自登陆的话 自登陆完成 - setTimeout(function(){ + setTimeout(function() { uni.navigateTo({ - url:'/pages/login/showlogin' + url: '/pages/login/showlogin' }) - },1500); + }, 1500); return; } createSign(_reqObj); - + uni.request(_reqObj); } @@ -127,7 +144,7 @@ export function request(_reqObj) { * @param {Object} _reqObj 请求参数 */ export function requestNoAuth(_reqObj) { - debug('java110Request','requestNoAuth',_reqObj); + debug('java110Request', 'requestNoAuth', _reqObj); //这里判断只有在 post 方式时 放加载框 if (_reqObj.hasOwnProperty("method") && "POST" == _reqObj.method) { uni.showLoading({ @@ -148,6 +165,6 @@ export function requestNoAuth(_reqObj) { _reqObj.header = _headers; } createSign(_reqObj); - + uni.request(_reqObj); -} +} \ No newline at end of file