4 changed files with 960 additions and 1005 deletions
File diff suppressed because it is too large
@ -1,220 +1,219 @@ |
|||||
import Vue from 'vue' |
import Vue from 'vue' |
||||
import axios from 'axios' |
import axios from 'axios' |
||||
import qs from 'qs' |
import qs from 'qs' |
||||
import md5 from 'js-md5'; |
import md5 from 'js-md5'; |
||||
import constant from './constant.js'; |
import constant from './constant.js'; |
||||
|
|
||||
let baseURL = ''; |
let baseURL = ''; |
||||
let key = ''; |
let key = ''; |
||||
// #ifdef H5
|
// #ifdef H5
|
||||
baseURL = constant.H5 |
baseURL = constant.H5 |
||||
key = constant.H5_KEY |
key = constant.H5_KEY |
||||
// #endif
|
// #endif
|
||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||
baseURL = constant.APP |
baseURL = constant.APP |
||||
key = constant.APP_KEY |
key = constant.APP_KEY |
||||
// #endif
|
// #endif
|
||||
const service = axios.create({ |
const service = axios.create({ |
||||
withCredentials: true, |
withCredentials: true, |
||||
crossDomain: true, |
crossDomain: true, |
||||
baseURL, |
baseURL: constant.BASE_URL, |
||||
timeout: 160000 |
timeout: 160000 |
||||
}) |
}) |
||||
|
console.log(constant.BASE_URL) |
||||
// request拦截器,在请求之前做一些处理
|
|
||||
service.interceptors.request.use( |
// request拦截器,在请求之前做一些处理
|
||||
config => { |
service.interceptors.request.use( |
||||
// console.log('showDialog' + Vue.prototype.$showDialog)
|
config => { |
||||
if (Vue.prototype.$showDialog) { |
const language = uni.getStorageSync("language") || 'en_US'; |
||||
uni.showLoading({ |
console.log('语言', uni.getStorageSync('language')) |
||||
title: 'loading', |
if (constant.SHOW_DIALOG) { |
||||
mask: true |
uni.showLoading({ |
||||
}) |
title: 'loading', |
||||
} |
mask: true |
||||
const ticket = uni.getStorageSync('ticket') |
}) |
||||
let dataStr = []; |
} |
||||
if (config.method == 'get') { |
if (config.url.indexOf('market') > -1) { |
||||
if (config.url.split('?').length > 1) { |
config.baseURL = Vue.prototype.MARKET_URL; |
||||
dataStr = config.url.split('?')[1].split('&'); |
} |
||||
} |
const ticket = uni.getStorageSync('ticket') |
||||
|
if (ticket != '') { |
||||
} |
config.data['ticket'] = ticket |
||||
|
} |
||||
|
if (Vue.prototype.$showDialog) { |
||||
|
uni.showLoading({ |
||||
|
title: 'loading', |
||||
|
mask: true |
||||
|
}) |
||||
|
} |
||||
|
// if (store.state.token) {
|
||||
|
// // 给请求头添加user-token
|
||||
|
// config.headers["user-token"] = store.state.token;
|
||||
|
// }
|
||||
|
//const ticket = Vue.prototype.$store.state.ticket
|
||||
|
|
||||
|
|
||||
|
let dataStr = []; |
||||
|
if (config.method == 'get') { |
||||
|
|
||||
|
if (config.url.split('?').length > 1) { |
||||
|
dataStr = config.url.split('?')[1].split('&'); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
if (config.method == 'post') { |
if (config.method == 'post') { |
||||
dataStr = qs.stringify(config.data).split('&'); |
console.log(config.data) |
||||
// dataStr = JSON.stringify(config.data);
|
dataStr = config.data.split('&'); |
||||
// dataStr = config.data;
|
|
||||
|
|
||||
// dataStr = config.data.name;
|
|
||||
|
} |
||||
} |
//console.log(config.url,111111,config.data,dataStr)
|
||||
config.data = {}; |
config.data = {}; |
||||
dataStr.forEach(function (e) { |
|
||||
console.log(e, 666666) |
dataStr.forEach(function(e) { |
||||
config.data[e.split('=')[0]] = e.split('=')[1]; |
config.data[e.split('=')[0]] = e.split('=')[1]; |
||||
}); |
}); |
||||
// console.log(ticket)
|
|
||||
if (ticket != '') { |
|
||||
config.data['ticket'] = ticket |
var keys = []; |
||||
} |
let sign = ''; |
||||
var keys = []; |
|
||||
let sign = ''; |
var t = Date.now() - 2901; |
||||
for (var k in config.data) |
// config.headers["timestamp"] = t;
|
||||
keys.push(k); |
// config.data["timestamp"] = t
|
||||
keys.sort(function (a, b) { |
|
||||
return a < b ? -1 : 1; |
for (var k in config.data) |
||||
}) |
keys.push(k); |
||||
// console.log("keys===========");
|
keys.sort(function(a, b) { |
||||
keys.forEach(function (e) { |
return a < b ? -1 : 1; |
||||
if (config.data[e] || config.data[e] == '') { |
}) |
||||
sign += e + '=' + config.data[e] + '&' |
|
||||
} |
|
||||
|
//console.log("keys===========",keys);
|
||||
}); |
|
||||
|
|
||||
// console.log("签名参数===========");
|
keys.forEach(function(e) { |
||||
// console.log(config.url);
|
|
||||
// console.log(sign + key);
|
if (config.data[e] || config.data[e] == '') { |
||||
sign = md5(sign + key); |
sign += e + '=' + config.data[e] + '&' |
||||
// console.log("提交参数===========");
|
} |
||||
// console.log(qs.stringify(config.data));
|
|
||||
if (config.method == 'post') { |
}); |
||||
// console.log(config.data,666666)
|
|
||||
config.data['sign'] = sign |
|
||||
config.data = qs.stringify(config.data) |
key = "key=" + constant.KEY; |
||||
// config.data = config.data.replace(/(\w+)\s*, \s*(\w+)/, "$2 $1");
|
sign = md5(sign + key); |
||||
// if(config.url == ){
|
config.data['timestamp'] = null |
||||
|
if (config.method == 'post') { |
||||
// #ifdef H5
|
config.data['sign'] = sign |
||||
if (config.url == '/api/index/goodsList') { |
|
||||
config.data = config.data.replaceAll('20', ""); |
config.data = qs.stringify(config.data).replace("timestamp=&", "") |
||||
config.data = config.data.replaceAll('26', ""); |
|
||||
config.data = config.data.replaceAll('2F', "/"); |
|
||||
config.data = config.data.replaceAll('28', ""); |
} |
||||
config.data = config.data.replaceAll('29', ""); |
if (config.method == 'get') { |
||||
// config.data = config.data.replaceAll('%C2%AE', "®");
|
|
||||
} |
config.url = config.url + '&sign=' + sign |
||||
// #endif
|
} |
||||
// #ifdef APP-PLUS
|
|
||||
if (config.url == '/api/index/goodsList') { |
return config; |
||||
config.data = config.data.replace(new RegExp('20', "gm"), ""); |
}, |
||||
config.data = config.data.replace(new RegExp('26', "gm"), ""); |
error => { |
||||
config.data = config.data.replace(new RegExp('2F', "gm"), "/"); |
// console.log(error); // for debug
|
||||
config.data = config.data.replace(new RegExp('28', "gm"), ""); |
uni.hideLoading(); |
||||
config.data = config.data.replace(new RegExp('29', "gm"), ""); |
return Promise.reject(error); |
||||
// config.data = config.data.replaceAll('%C2%AE', "®");
|
} |
||||
} |
); |
||||
// #endif
|
|
||||
|
//配置成功后的拦截器
|
||||
|
service.interceptors.response.use(res => { |
||||
// config.data = config.data.replaceAll('2528',"(");
|
console.log('过期了吗', res) |
||||
// config.data = config.data.replaceAll('2529',")");
|
uni.hideLoading() |
||||
// config.data = config.data.replaceAll('252',"%2F");
|
// console.log(res)
|
||||
|
// console.log(res.data)
|
||||
// }
|
// console.log(res.data.data[0].nameAlias)
|
||||
|
if (res.data.success || res.data.errCode === 'USER.0017') { |
||||
} |
// console.log(res.data.success)
|
||||
if (config.method == 'get') { |
return res.data |
||||
if (ticket != '') { |
} else { |
||||
config.url = config.url + '&ticket=' + ticket + '&sign=' + sign |
uni.showToast({ |
||||
} else { |
title: res.data.errMsg, |
||||
config.url = config.url + '?sign=' + sign |
icon: 'none', |
||||
} |
duration: 1500 |
||||
} |
}) |
||||
// console.log(config)
|
if (res.data.errCode === 'USER.0010') { |
||||
return config; |
|
||||
}, |
uni.removeStorage({ |
||||
error => { |
key: 'logInfo', |
||||
// console.log(error); // for debug
|
success: function(res) { |
||||
return Promise.reject(error); |
uni.reLaunch({ |
||||
} |
url: '/pages/login/index' |
||||
); |
}) |
||||
|
}, |
||||
//配置成功后的拦截器
|
fail: (err) => {} |
||||
service.interceptors.response.use(res => { |
}); |
||||
console.log('过期了吗') |
|
||||
uni.hideLoading() |
|
||||
// console.log(res)
|
// #ifdef H5
|
||||
// console.log(res.data)
|
var url = location.href; |
||||
// console.log(res.data.data[0].nameAlias)
|
if (url.indexOf('pages') > -1) { |
||||
if (res.data.success || res.data.errCode === 'USER.0017') { |
uni.setStorage({ |
||||
// console.log(res.data.success)
|
key: 'url', |
||||
return res.data |
data: url, |
||||
} else { |
success: function() { |
||||
uni.showToast({ |
console.log('success') |
||||
title: res.data.errMsg, |
} |
||||
icon: 'none', |
}); |
||||
duration: 1500 |
} else { |
||||
}) |
uni.removeStorageSync('url') |
||||
if (res.data.errCode === 'USER.0010') { |
} |
||||
|
// #endif
|
||||
uni.removeStorage({ |
|
||||
key: 'logInfo', |
|
||||
success: function (res) { |
} |
||||
uni.reLaunch({ url: '/pages/login/index' }) |
uni.$emit('refreshQrCode') |
||||
}, |
return Promise.reject(res.data.errMsg); |
||||
fail: (err) => { |
} |
||||
} |
}, error => { |
||||
}); |
uni.hideLoading(); |
||||
|
return Promise.reject(error) |
||||
|
}) |
||||
// #ifdef H5
|
|
||||
var url = location.href; |
|
||||
if (url.indexOf('pages') > -1) { |
axios.defaults.adapter = function(config) { //自己定义个适配器,用来适配uniapp的语法
|
||||
uni.setStorage({ |
return new Promise((resolve, reject) => { |
||||
key: 'url', |
// console.log(config)
|
||||
data: url, |
var settle = require('axios/lib/core/settle'); |
||||
success: function () { |
var buildURL = require('axios/lib/helpers/buildURL'); |
||||
console.log('success') |
uni.request({ |
||||
} |
method: config.method.toUpperCase(), |
||||
}); |
url: config.baseURL + buildURL(config.url, config.params, config.paramsSerializer), |
||||
} else { |
header: config.headers, |
||||
uni.removeStorageSync('url') |
data: config.data, |
||||
} |
dataType: config.dataType, |
||||
// #endif
|
responseType: config.responseType, |
||||
|
sslVerify: config.sslVerify, |
||||
|
complete: function complete(response) { |
||||
} |
//console.log("执行完成:",config.baseURL + buildURL(config.url, config.params, config.paramsSerializer),response.data)
|
||||
uni.$emit('refreshQrCode') |
response = { |
||||
return Promise.reject(res.data.errMsg); |
data: response.data, |
||||
} |
status: response.statusCode, |
||||
}, error => { |
errMsg: response.errMsg, |
||||
return Promise.reject(error) |
header: response.header, |
||||
}) |
config: config |
||||
|
}; |
||||
|
|
||||
axios.defaults.adapter = function (config) { //自己定义个适配器,用来适配uniapp的语法
|
settle(resolve, reject, response); |
||||
return new Promise((resolve, reject) => { |
}, |
||||
// console.log(config)
|
fail: res => { |
||||
var settle = require('axios/lib/core/settle'); |
uni.showLoading({ |
||||
var buildURL = require('axios/lib/helpers/buildURL'); |
title: res, |
||||
uni.request({ |
mask: true |
||||
method: config.method.toUpperCase(), |
}) |
||||
url: config.baseURL + buildURL(config.url, config.params, config.paramsSerializer), |
} |
||||
header: config.headers, |
}) |
||||
data: config.data, |
}) |
||||
dataType: config.dataType, |
} |
||||
responseType: config.responseType, |
|
||||
sslVerify: config.sslVerify, |
|
||||
complete: function complete(response) { |
|
||||
//console.log("执行完成:",config.baseURL + buildURL(config.url, config.params, config.paramsSerializer),response.data)
|
|
||||
response = { |
|
||||
data: response.data, |
|
||||
status: response.statusCode, |
|
||||
errMsg: response.errMsg, |
|
||||
header: response.header, |
|
||||
config: config |
|
||||
}; |
|
||||
|
|
||||
settle(resolve, reject, response); |
|
||||
}, |
|
||||
fail: res => { |
|
||||
uni.showToast({ |
|
||||
title: res, |
|
||||
icon: 'none', |
|
||||
duration: 1500 |
|
||||
}) |
|
||||
} |
|
||||
}) |
|
||||
}) |
|
||||
} |
|
||||
export default service |
export default service |
||||
|
@ -1,14 +1,14 @@ |
|||||
const H5 = '/start'; |
const IS_TEST = true; |
||||
const H5_KEY = 'key=PBcGdWvA7dUintx7WNOR11cOdCrEpasM'; |
const BASE_URL = IS_TEST?'https://sapi.payairs.com':''; |
||||
|
const MARKET_URL = IS_TEST?'https://market.acefinex.com':''; |
||||
const APP = 'https://api.wingold6.com'; //正式
|
const KEY = IS_TEST?'jsabdjhfbsjndfksnjndja,sndmbstart':''; |
||||
// const APP = 'https://apitest.luck-work.com'; //测试
|
const WSSURL = IS_TEST?'wss://market.acefinex.com/wss/':''; |
||||
const APP_KEY = 'key=PBcGdWvA7dUintx7WNOR11cOdCrEpasM'; |
const SHOW_DIALOG=true |
||||
const showDialog = true |
|
||||
export default { |
export default { |
||||
H5, |
IS_TEST, |
||||
H5_KEY, |
BASE_URL, |
||||
APP, |
MARKET_URL, |
||||
APP_KEY, |
KEY, |
||||
showDialog, |
WSSURL, |
||||
|
SHOW_DIALOG |
||||
} |
} |
Loading…
Reference in new issue