deguodaigou/utils/bin.js

80 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2019-12-23 10:04:09 +08:00
//请求接口
let request = function (obj){
2019-12-24 16:32:27 +08:00
wx.showLoading({
title: '加载中',
mask:true
})
2019-12-23 10:04:09 +08:00
let {
url,
data,
method,
header,
dataType,
responseType,
complete,
name,
urldata
} = obj
2019-12-24 14:08:26 +08:00
url="https://daigou.sdbairui.com/index.php/WXAPI/" + url
2019-12-23 10:04:09 +08:00
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)
2019-12-24 16:32:27 +08:00
2019-12-23 10:04:09 +08:00
},
fail(data){
rej(data)
},
2019-12-24 16:32:27 +08:00
complete(){
wx.hideLoading()
}
2019-12-23 10:04:09 +08:00
})
})
}
2019-12-23 16:53:54 +08:00
let getuserid = function(){
2019-12-23 10:04:09 +08:00
return new Promise((res,rej)=>{
request({
url:"User/validateOpenid"
}).then((r)=>{
2019-12-24 16:32:27 +08:00
if(r.data.code == 400){
res(0)
}else{
res(r.data.data.user_id)
}
2019-12-23 10:04:09 +08:00
})
})
}
module.exports = {
2019-12-23 16:53:54 +08:00
request,getuserid
2019-12-13 10:29:54 +08:00
}