This commit is contained in:
魏啾
2024-04-30 18:07:59 +08:00
parent b72c4d7af1
commit 56863dd624
1369 changed files with 156460 additions and 0 deletions

37
framework/sign.js Normal file
View 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
}
})