var constant = require('./constant.js')
var access_token;
var requestHandler = {
params: {},
API_URL: '',
token: '',
success: function (res) {
// success
},
fail: function () {
// fail
},
}
//GET请求
function GET(requestHandler) {
request('GET', requestHandler)
}
//POST请求
function POST(requestHandler) {
request('POST', requestHandler)
}
function request(method, requestHandler) {
//注意:可以对params加密等处理
var params = requestHandler.params;
var API_URL = requestHandler.API_URL;
// wx.showLoading({
// title: '加载中',
// })
wx.request({
url: `${constant.B_TO_C}${API_URL}`,
data: params,
method: method,
header: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', // 默认值,
// 'Authorization': "Bearer " + wx.getStorageSync('login').access_token
}, // 设置请求的 header
success: function (res) {
if (res.statusCode == 500) {
wx.showToast({
title: '系统繁忙',
icon: 'none',
duration: 1500
})
}
// wx.hideLoading();
//注意:可以对参数解密等处理
requestHandler.success(res)
},
fail: function (res) {
// wx.hideLoading();
requestHandler.fail()
},
complete: function (res) {
// wx.hideLoading();
// complete
}
})
}
module.exports = {
GET: GET,
POST: POST
}