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.
43 lines
943 B
43 lines
943 B
4 years ago
|
const baseURL = 'https://some-domain.com/api/'
|
||
|
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',
|
||
|
};
|
||
|
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, `jsapi/mini?jsCode=${data}`),
|
||
|
};
|
||
|
module.exports = {
|
||
|
API: API
|
||
|
}
|