deguodaigou/utils/bin.js
2019-12-20 09:51:28 +08:00

57 lines
1.1 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){
if(urldata[i] == undefined){
text += `/${i}`
}else{
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
}