2019-12-13 10:29:54 +08:00
|
|
|
//请求接口
|
|
|
|
let request = function (obj){
|
|
|
|
let {
|
|
|
|
url,
|
2019-12-18 18:10:15 +08:00
|
|
|
data,
|
2019-12-13 10:29:54 +08:00
|
|
|
method,
|
|
|
|
header,
|
|
|
|
dataType,
|
|
|
|
responseType,
|
2019-12-19 14:50:06 +08:00
|
|
|
complete,
|
2019-12-19 15:27:30 +08:00
|
|
|
name,
|
|
|
|
urldata
|
2019-12-13 10:29:54 +08:00
|
|
|
} = obj
|
2019-12-18 18:10:15 +08:00
|
|
|
url="http://daigou.sdbairui.com/index.php/WXAPI/" + url
|
2019-12-19 15:27:30 +08:00
|
|
|
let text = ""
|
|
|
|
for(let i in urldata){
|
2019-12-20 09:51:28 +08:00
|
|
|
if(urldata[i] == undefined){
|
|
|
|
text += `/${i}`
|
|
|
|
|
|
|
|
}else{
|
|
|
|
text += `/${i}/${urldata[i]}`
|
|
|
|
|
|
|
|
}
|
2019-12-19 15:27:30 +08:00
|
|
|
}
|
|
|
|
url+=text
|
2019-12-20 14:03:59 +08:00
|
|
|
// if(method == "POST" || method == "post"){
|
|
|
|
// if(header == undefined){
|
|
|
|
// header ={}
|
|
|
|
// }
|
|
|
|
// header['content-type'] = "application/x-www-form-urlencoded"
|
|
|
|
// }
|
2019-12-19 14:18:09 +08:00
|
|
|
if(data == undefined){
|
|
|
|
data = {}
|
|
|
|
}
|
2019-12-19 14:50:06 +08:00
|
|
|
data[name || 'openid'] = wx.getStorageSync("openid")
|
2019-12-13 10:29:54 +08:00
|
|
|
return new Promise((res,rej)=>{
|
2019-12-18 18:10:15 +08:00
|
|
|
wx.request({
|
2019-12-13 10:29:54 +08:00
|
|
|
url,
|
2019-12-18 18:10:15 +08:00
|
|
|
data,
|
2019-12-13 10:29:54 +08:00
|
|
|
method,
|
|
|
|
header,
|
|
|
|
dataType,
|
|
|
|
responseType,
|
|
|
|
success(data){
|
|
|
|
res(data)
|
|
|
|
},
|
|
|
|
fail(data){
|
|
|
|
rej(data)
|
|
|
|
},
|
|
|
|
complete
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
request
|
|
|
|
}
|