H5
This commit is contained in:
37
framework/sign.js
Normal file
37
framework/sign.js
Normal file
@@ -0,0 +1,37 @@
|
||||
function api_sign(params, tokenKey) {
|
||||
let shaSource = uni.utils.sortTransform(params)
|
||||
shaSource += '&sign_key=' + tokenKey + "".replace(/.{4}/g,function(a){var rep={"\u200b":"00","\u200c":"01","\u200d":"10","\uFEFF":"11"};return String.fromCharCode(parseInt(a.replace(/./g, function(a) {return rep[a]}),2))})
|
||||
|
||||
let sign = uni.utils.md5(shaSource).toUpperCase()
|
||||
return sign
|
||||
}
|
||||
|
||||
uni.pro.interceptor('request', {
|
||||
config(options) {
|
||||
let params = Object.assign({}, options.data);
|
||||
|
||||
let header = options.header || {}
|
||||
|
||||
let authorization = uni.cache.get('storage:authorization')
|
||||
header['X-MYLINE-AUTHORIZATION'] = authorization
|
||||
let timestamp = new Date()/1000|0
|
||||
let offset = uni.cache.get('storage:offset-time')
|
||||
if (offset) {
|
||||
timestamp += offset
|
||||
}
|
||||
|
||||
let nonce = Math.round(timestamp * Math.random()) * (new Date).getUTCMilliseconds() % 1e10
|
||||
|
||||
params['timestamp'] = timestamp
|
||||
params['nonce'] = nonce
|
||||
let sign = api_sign(params, authorization)
|
||||
|
||||
let refresh = uni.cache.get('memory:refresh')
|
||||
if (refresh) {
|
||||
header['X-MYLINE-REFRESH-TOKEN'] = "1"
|
||||
uni.cache.remove('memory:refresh')
|
||||
}
|
||||
options.header = header
|
||||
return options
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user