let baseurl = 'http://192.168.6.75'; let pathname = document.location.href; //开发环境 if (pathname.includes('1688sup') || pathname.includes('83323') || pathname.includes('86885') || pathname.includes('22233')) { //正式 baseurl = 'https://marketapi.1688sup.com' } if (pathname.includes('test')) { baseurl = 'http://192.168.6.75'; } //统一请求 axios.interceptors.request.use((config) => { config.headers.Version = 'v1.2.0'; return config }) const req = { //获取落地页信息 axiosGetplan(url, params) { var result = axios({ method: 'get', url: baseurl + url, params, }).then(function (res) { return res.data; }).catch(function (error) { alert("服务器错误"); return; }); return result; }, //发送key手机号核销验证码 axiosPostsendMobile(url, data) { let result = axios({ method: 'post', url: baseurl + url, data: data, header: { 'Content-type': 'application/x-www-form-urlencoded' } }).then(res => { return res.data; }).catch(error => { alert("服务器错误"); return "exception=" + error; }); return result; }, //获取key列表 axiosPostgetKey(url, data) { let result = axios({ method: 'post', url: baseurl + url, data: data, header: { 'Content-type': 'application/x-www-form-urlencoded' } }).then(res => { return res; }).catch(error => { alert("服务器错误"); return "exception=" + error; }); return result; }, //免验证登录 axiosPostTogppds(url, data) { let result = axios({ method: 'post', url: baseurl + url, data: data, header: { 'Content-type': 'application/x-www-form-urlencoded' } }).then(res => { return res.data; }).catch(error => { alert("服务器错误"); return "exception=" + error; }); return result; }, //验证key信息 axiosPostKey(url, data) { let result = axios({ method: 'post', url: baseurl + url, data: data, header: { 'Content-type': 'application/x-www-form-urlencoded' } }).then(res => { return res.data; }).catch(error => { alert("服务器错误"); return "exception=" + error; }); return result; }, //获取key相关的商品信息 axiosPostproducts(url, data) { let result = axios({ method: 'post', url: baseurl + url, data: data, header: { 'Content-type': 'application/x-www-form-urlencoded' } }).then(res => { return res.data; }).catch(error => { alert("服务器错误"); return "exception=" + error; }); return result; }, //key核销生成订单 axiosPostusage(url, data) { let result = axios({ method: 'post', url: baseurl + url, data: data, header: { 'Content-type': 'application/x-www-form-urlencoded' } }).then(res => { return res.data; }).catch(error => { alert("服务器错误"); return "exception=" + error; }); return result; }, //查询兑换订单接口 axiosPostResult(url, data) { let result = axios({ method: 'post', url: baseurl + url, data: data, header: { 'Content-type': 'application/x-www-form-urlencoded' } }).then(res => { return res.data; }).catch(error => { alert("服务器错误"); return "exception=" + error; }); return result; }, } //图形验证码 function captchaimg() { let parmas = {} let customsessionid = ""; const xhr = new XMLHttpRequest() xhr.open('GET', baseurl + '/auth/login/verify') xhr.setRequestHeader('Version', 'v1.1.0'); xhr.responseType = "arraybuffer"; xhr.onreadystatechange = function (response) { response.header = { 'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', } var img = document.getElementById('captcha_img') var byteArray = new Uint8Array(response.target.response); var binary = ''; for (var i = 0; i < byteArray.byteLength; i++) { binary += String.fromCharCode(byteArray[i]); } let str = 'data:image/png;base64,' + window.btoa(binary) img.src = str; customsessionid = xhr.getResponseHeader('Unique-Str'); sessionStorage.setItem('unique_str', customsessionid); } xhr.send() }