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.
|
|
|
const baseURL = 'http://139.159.180.147:9002/'
|
|
|
|
const GET = 'GET';
|
|
|
|
const POST = 'POST';
|
|
|
|
const PUT = 'PUT';
|
|
|
|
const FORM = 'FORM';
|
|
|
|
const DELETE = 'DELETE';
|
|
|
|
|
|
|
|
|
|
|
|
function request(method, url, data) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
let header = {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
'Authorization': 'Basic YXBwOmFwcA==',
|
|
|
|
};
|
|
|
|
wx.request({
|
|
|
|
url: baseURL + url,
|
|
|
|
method: method,
|
|
|
|
data: method === POST ? JSON.stringify(data) : data,
|
|
|
|
header: header,
|
|
|
|
success(res) {
|
|
|
|
//请求成功
|
|
|
|
//判断状态码---errCode状态根据后端定义来判断
|
|
|
|
if (res.data.errCode == 0) {
|
|
|
|
resolve(res);
|
|
|
|
} else {
|
|
|
|
//其他异常
|
|
|
|
reject('运行时错误,请稍后再试');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fail(err) {
|
|
|
|
//请求失败
|
|
|
|
reject(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const API = {
|
|
|
|
getOpenid: (data) => request(GET, `oauth/token?grant_type=password&username=${data.admin}&password=${data.password}`),
|
|
|
|
getUserAuth: (data) => request(POST, `social/token?code=MINI@${data}`)
|
|
|
|
};
|
|
|
|
module.exports = {
|
|
|
|
API: API
|
|
|
|
}
|