mobileclient/api1_1.js

176 lines
4.3 KiB
JavaScript
Raw Normal View History

2022-01-20 14:45:21 +08:00
let baseurl = 'http://192.168.6.75';
let testZyg = 'http://192.168.6.81:8056';
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.0.3';
return config
})
const req = {
//获取落地页信息
axiosGetplan(url, params){
var result = axios({
method: 'get',
url: baseurl + url,
params,
}).then(function(res) {
if(res.data.code!=200){
alert(res.data.message);
return false;
}
return res.data;
}).catch(function(error) {
return "exception=" + error;
});
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 => {
return "exception=" + error;
});
return result;
},
//获取key列表
axiosPostgetKey(url, data) {
let result = axios({
method: 'post',
url: testZyg + url,
data: data,
header: {
'Content-type': 'application/x-www-form-urlencoded'
}
}).then(res => {
return res;
}).catch(error => {
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 => {
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 => {
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 => {
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 => {
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 => {
return "exception=" + error;
});
return result;
},
}
//图形验证码
function captchaimg(){
let self = this;
let parmas = {}
let customsessionid="";
const xhr = new XMLHttpRequest()
xhr.open('GET', baseurl + '/auth/login/verify')
xhr.setRequestHeader('Version','v1.0.3');
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()
}