有一段js代码
const CryptoJS = require("crypto-js")
function l(t, e) {
return t.toString().toUpperCase() > e.toString().toUpperCase() ? 1 : t.toString().toUpperCase() == e.toString().toUpperCase() ? 0 : -1
}
function u(t) {
for (var e = Object.keys(t).sort(l), n = "", a = 0; a < e.length; a++)
if (void 0 !== t[e[a]])
if (t[e[a]] && t[e[a]]instanceof Object || t[e[a]]instanceof Array) {
var i = JSON.stringify(t[e[a]]);
n += e[a] + i
} else
n += e[a] + t[e[a]];
return n
}
function d(t) {
for (var e in t)
"" !== t[e] && void 0 !== t[e] || delete t[e];
var n = "B3978D054A72A7002063637CCDF6B2E5" + u(t);
return CryptoJS.MD5(n).toString().toLocaleLowerCase()
}
python 调用
import execjs
# 读文件
js_code = open("1.js").read()
# execjs.compile运行代码
js_compile = execjs.compile(js_code)
# 参数
json_data = {
'pageSize': 8,
'type': '12',
'ts': 1721372555517,
}
sign = js_compile.call("d", json_data) # 调用d函数,传参数
print(sign)
标签:python,toUpperCase,js,compile,toString,var,execjs,加载
From: https://www.cnblogs.com/a438842265/p/18311511