You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

75 lines
1.8 KiB

// let baseUrl = 'http://192.168.66.219:8000/api'
let baseUrl = 'https://intp.xingtongworld.com'
let API = {
baseUrl: baseUrl,
// 获取微信授权登录基本信息
getWxCode(data, success, fail){
API.sendRequest('get', data, '/wechat/login/getWxCode', success, fail)
},
// 获取微信code进行登录
wx(data, success, fail){
API.sendRequest('get', data, '/wechat/login/wx', success, fail)
},
// 通用api
request(url, data, success, fail, boolean=true){
API.sendRequest('post', data, url, success, fail, boolean)
},
// 请求
sendRequest(method, data, url, success, fail, boolean){
let types = '';
if (method == 'POST') {
types = 'application/x-www-form-urlencoded'
} else {
types = 'application/json';
}
let requestObj = {}
if(boolean){
requestObj.header = {
'Content-Type': types,
'Accept': 'application/json, text/javascript, */*; q=0.01',
// 'Authorization': uni.getStorageSync('user_token')||''
'token': uni.getStorageSync('AccessToken')||''
}
}
uni.request({
url:baseUrl+url,
method: method,
data: data,
...requestObj,
success(res) {
// 200=成功, 400 = 失败错误返回、404 token验证失败 ,403 token已过2小时失效
if(res.data.code == 1){
success && success(res.data);
return;
}
if(res.data.code == -14){
setTimeout(()=>{
uni.navigateTo({
url:"/pages/wxlogin/wxlogin"
})
},3000)
}
uni.showToast({
title: res.data.msg || res.msg,
icon: 'none'
})
// if(res.data.code==403 || res.data.code==201){
// uni.removeStorageSync('user_token');
// // setTimeout(()=>{
// // uni.reLaunch({
// // url: '/pages/login/login'
// // // url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
// // })
// // }, 1000)
// }
}
})
}
}
export default API;