deguodaigou/utils/bin.js
2019-12-23 16:53:54 +08:00

68 lines
1.4 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] === ''){
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
})
})
}
let getuserid = function(){
return new Promise((res,rej)=>{
request({
url:"User/validateOpenid"
}).then((r)=>{
res(r.data.data.user_id)
})
})
}
module.exports = {
request,getuserid
}