const
globalsetting =
require
(
'globalsetting.js'
)
const
baseURL = globalsetting.serverconst util =
require
(
'util.js'
)
const
ignoreUrls = [
'/auth/weChatLogin'
,
'/user/userBindingOpenId'
,
'/user/getSecret'
,
'/user/getOpenId'
]
var
token =
''
function
post(url, args) {
args = _prev(url,
'POST'
, args)
wx.request(args)
}
function
get(url, args) {
args = _prev(url,
'GET'
, args)
wx.request(args)
}
function
put(url, args) {
args = _prev(url,
'PUT'
, args)
wx.request(args)
}
function
_delete(url, args) {
args = _prev(url,
'DELETE'
, args)
wx.request(args)
}
function
_prev(url, method, args) {
args = args || {}
args.url = url
if
(args.urlparam)
args.url +=
'/'
+ args.urlparam
var
params = parseParams(args)
params.method = method
params.success = success(params.success)
params.fail = fail(params.fail)
setToken(params)
return
params
}
params.header = { token: getToken() }
else
params.header.token = getToken()
}
else
{
}
}
params.url = baseURL + params.url
if
(params.param) {
if
(params.url.indexOf(
'?'
) > -1 && params.url.indexOf(
'?'
) != params.url.length - 1) {
params.url +=
'&'
}
else
if
(params.url.indexOf(
'?'
) == params.url.length -1) {
}
else
{
params.url +=
'?'
}
var
buf =
''
for
(
var
name in params.param) { let val = params.param[name];
buf += name +
'='
+ encodeURI(typeof val ==
'object'
? JSON.stringify(val) : val) +
'&'
}
params.url += buf
}
return
params
}
util.errorMsg(
'请求失败405:\n服务器返回失败'
)
}
else
if
(status == 404) {
util.errorMsg(
'请求失败404:\n找不到接口'
)
}
if
(callback) callback(rs.data)
}
}
function
fail(callback) {
return
function
(rs) { console.log(rs)
if
(callback) callback(rs)
}
}
token = tk
wx.setStorageSync(
'token'
, token)
}复制代码
暂时没有评论,来抢沙发吧~