You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
const baseURL = 'http://139.159.180.147:9002/' |
|
const GET = 'GET'; |
|
const POST = 'POST'; |
|
const PUT = 'PUT'; |
|
const FORM = 'FORM'; |
|
const DELETE = 'DELETE'; |
|
|
|
|
|
function request(method, url, data,hasToke=true) { |
|
let token = wx.getStorageSync('access_token') |
|
let Authorization =token&&hasToke?`Bearer ${token}`:'Basic YXBwOmFwcA==' |
|
return new Promise(function (resolve, reject) { |
|
let header = { |
|
'content-type': 'application/json', |
|
'Authorization': Authorization, |
|
}; |
|
wx.request({ |
|
url: baseURL + url, |
|
method: method, |
|
data: method === POST ? JSON.stringify(data) : data, |
|
header: header, |
|
success(res) { |
|
resolve(res.data); |
|
}, |
|
fail(err) { |
|
//请求失败 |
|
reject(err) |
|
} |
|
}) |
|
}) |
|
} |
|
|
|
|
|
const API = { |
|
getOpenid: (data) => request(GET, `oauth/token?grant_type=password&username=${data.admin}&password=${data.password}`), |
|
getUserAuth: (data) => request(POST, `social/token?code=MINI@${data}`,'',false), |
|
registerBind: (data) => request(POST, `social/register-bind`, data,false), |
|
getUserInfo: () => request(GET, `user/info`), //获取用户信息 |
|
}; |
|
module.exports = { |
|
API: API |
|
} |