This commit is contained in:
cwchen 2024-11-18 10:56:52 +08:00
parent 1d6746cc1b
commit 8083f0e89a
2 changed files with 78 additions and 3 deletions

View File

@ -89,3 +89,23 @@ function dateFtt(fmt, date) { //author: meizz
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
function encryptCBC(word){
var cbc_key = CryptoJS.enc.Utf8.parse("zhgd@bonus@zhgd@bonus@1234567890");
var cbc_iv = CryptoJS.enc.Utf8.parse("1234567812345678");
var srcs = CryptoJS.enc.Utf8.parse(word)
var encrypted = CryptoJS.AES.encrypt(srcs, cbc_key, {
iv: cbc_iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
function generateToken(){
// 获取当前时间戳(以秒为单位)
const currentTimeStamp = Math.floor(Date.now());
// 将时间戳转换为字符串
const timeStampString = currentTimeStamp.toString();
return encryptCBC(timeStampString);
}

View File

@ -181,7 +181,62 @@ function getUrlParam(key) {
// 预览文件
function commonViewFile(params) {
let path = fileUrl + params + "&auth=" + sessionStorage.getItem("gz-token");
let time = encrypt(Math.floor(Date.now()).toString())
window.open(viewFileUrl + path + '&token=' + encrypt(time));
let path = fileUrl + params;
let encodePath = encodeURIComponent(useBase64.encode64(path));
window.open(viewFileUrl + encodePath + '&token=' + generateToken());
}
let _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
const useBase64 = {
encode64:(e) => {
let t = "";
let f = 0;
e = useBase64.encodeUTF8(e);
while (f < e.length) {
const n = e.charCodeAt(f++);
const r = e.charCodeAt(f++);
const i = e.charCodeAt(f++);
let s = n >> 2;
let o = (n & 3) << 4 | r >> 4;
let u = (r & 15) << 2 | i >> 6;
let a = i & 63;
if (isNaN(r)) {
u = a = 64;
} else if (isNaN(i)) {
a = 64;
}
t += _keyStr[s] + _keyStr[o] + _keyStr[u] + _keyStr[a];
}
return t;
},
decode64: (e) => {
let t = "";
let f = 0;
e = e.replace(/[^A-Za-z0-9+/=]/g, "");
while (f < e.length) {
const s = _keyStr.indexOf(e.charAt(f++));
const o = _keyStr.indexOf(e.charAt(f++));
const u = _keyStr.indexOf(e.charAt(f++));
const a = _keyStr.indexOf(e.charAt(f++));
let n = s << 2 | o >> 4;
let r = (o & 15) << 4 | u >> 2;
let i = (u & 3) << 6 | a;
t += String.fromCharCode(n);
if (u !== 64) {
t += String.fromCharCode(r);
}
if (a !== 64) {
t += String.fromCharCode(i);
}
}
return useBase64.decodeUTF8(t);
},
encodeUTF8: (input) => {
return unescape(encodeURIComponent(input));
},
decodeUTF8: (input) => {
return decodeURIComponent(escape(input));
},
}