deguodaigou/utils/bin.js
2019-12-19 15:27:30 +08:00

51 lines
1.0 KiB
JavaScript

//请求接口
let request = function (obj){
let {
url,
data,
method,
header,
dataType,
responseType,
complete,
name,
urldata
} = obj
url="http://daigou.sdbairui.com/index.php/WXAPI/" + url
let text = ""
for(let i in urldata){
text += `/${i}/${urldata[i]}`
}
url+=text
if(method == "POST" || method == "post"){
if(header == undefined){
header ={}
}
header['content-type'] = "application/x-www-form-urlencoded"
}
if(data == undefined){
data = {}
}
data[name || 'openid'] = wx.getStorageSync("openid")
return new Promise((res,rej)=>{
wx.request({
url,
data,
method,
header,
dataType,
responseType,
success(data){
res(data)
},
fail(data){
rej(data)
},
complete
})
})
}
module.exports = {
request
}