You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

295 lines
9.8 KiB

const CryptoJS = require('crypto-js');
logger = console.info;
class FpCrypt {
cookie = "";
publicKey = {
publicKey: "", tokenKey: ""
};
constructor(cookies, publicKey) {
this.cookie = cookies
if (publicKey) {
this.publicKey = publicKey
}
}
/**
* 处理 url 后缀
* @param t url
* @param e
* @returns {*}
*/
handleSuffix(t, e) {
var a = '1|4|2|0|3'['split']("|"),
c = 0, s, l, f, d, p, h;
if (!t) return t;
if (t['indexOf']('cssSecurity/v1/getPublicKey') > -1) return t;
if (t['indexOf']('qlfpcx/v1/queryFpjcxxDc') > -1) return t;
s = t;
l = this.Re();
// f = l['publicKey'];
d = l['tokenKey'];
// h = l['urlType'];
p = l['urlYzm'];
s = this.He(s, d, 0, e)
if (p) {
var u = (new Date)['valueOf']();
s += '&urls='['concat'](u)
}
logger(`处理url后缀${t} 完成返回${s}`)
return s;
}
/**
* 处理 Param
* @param t
* @param e
* @returns {{mesKey: string, enMesKey: string, enVal}}
*/
handleParam(t, e) {
var l = {
mesKey: "", enMesKey: "", enVal: t
};
if (t != null && t !== '') {
l['enVal'] = this.Ye(t, e);
}
logger(`处理返回`, l)
return l
}
He(t, e, n, o) {
var s = t;
if (s["indexOf"]("urlyzm=") > -1) return s;
s = this.Ke(s);
var l, f = (new Date)['valueOf'](),
d = (this.qe()["num"] % 2) === 0 ? (50 * Math['random'](1)) : (49 * Math['random']()) + 51;
console.log("tokenKey 加密方法选择", d, e)
// d = ((this.qe()['num'] % 2) === 0) ? (50 * Math['random'](1)) : (49 * Math['random']()) + 51;
if ((d >= 0) && (d <= 50)) {
l = this.Qs(f)
} else if ((d >= 51) && d <= 100) {
l = this.Qt(f, e)
}
var h = s['indexOf']("?") === (s["length"] - 1) ? "" : s['indexOf']("?") > -1 ? "&" : "?",
p = s += ""['concat'](h, "ruuid=")['concat'](f);
if (o) {
var v = p['split']("?")['splice'](1);
for (var b in v['map'](function (t) {
return t["split"]("=")[0]
}), o) {
if (!v["includes"](""["concat"](b))) {
if (('NenAk' !== 'NenAk')) {
// _0x2cc2bd("crypto");
} else {
var g = b["charAt"](0)['toUpperCase']();
b['length'] > 1 && (g += b['slice'](1));
var m = o[b];
(void 0 !== m) && (p += "&"["concat"](g, "=")["concat"](m))
}
}
}
}
var y = ""["concat"](l, "+")["concat"](p), x = this.he(y);
return s + ""["concat"](s["indexOf"]("?") ? "&" : "?", "urlyzm=")["concat"](encodeURIComponent(x))
}
Re() {
return this.publicKey;
}
Qs(t) {
var r = this.qe(), o = r['num'], u = r["tokenVal"],
s = (this.a(""['concat'](t)['split'](""))['join']("") + this.a(""['concat'](u)['split'](""))["join"]("")),
l = "";
for (var f = 0; (f < s['length']); f += o) {
var v = s["substring"](f, (f + o));
l += this.a(v['split'](""))['join']("")
}
return (((l["substring"](0, 5) + l['substring'](15, 20)) + l['substring'](5, 10)) + l['substring'](20, 25))
};
Qt(t, e) {
var r = this.qe(),
o = r['num'],
s = r['tokenVal'],
l = (this.a(""["concat"](t)['split'](""))["join"]("") + this.a(""["concat"](s)['split'](""))["join"]("")),
f = "";
for (var d = 0; d < l['length']; d += o) {
var h = l['substring'](d, d + o);
f += this.a(h['split'](""))['join']("")
}
var p = "",
v = e;
if (e) {
for (var b = 0; (b < v['length']); b += o) {
var g = v["substring"](b, b + o);
p += this.a(g["split"](""))["join"]("")
}
} else {
p = 'wk123med876dfesd57m72hnb3yfm98fs';
}
p = this.a(""['concat'](p)['split'](""))['join']("");
return (((f['substring'](0, 5) + p['substring'](5, 10)) + f['substring'](15, 20)) + p["substring"](20, 25))
}
Ye(t, e) {
var o = this.ke(32), a = "".concat(o).concat(t), c = this.Ue("", e);
return this.de(a, c)
}
ke(t, e) {
var n, i, a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""), c = [];
if (e = e || a.length, t) for (n = 0; n < t; n++) c[n] = a[0 | (Math["random"]() * e)]; else for (c[8] = c[13] = c[18] = c[23] = "-", c[14] = "4", n = 0; (n < 36); n++) c[n] || (i = 0 | (16 * Math["random"]()), c[n] = a[19 === n ? 8 | (3 & i) : i]);
logger(`生成随机 ${e} 位字符串`, c["join"](""))
return c["join"]("")
}
de(t, e) {
var o = this.le(e), a = this.le(t);
var res = CryptoJS.AES.encrypt(a, o, {
mode: CryptoJS.mode.ECB, //ECB模式
padding: CryptoJS.pad.Pkcs7 //padding处理
}).toString();
logger(`AES 加密:${t},${e} 加密所得${res}`)
return res;
}
le(t) {
return CryptoJS.enc.Utf8.parse(t)
}
Ue(t, e) {
var c = this.rt(t), u = this.Ke(e);
c = "".concat(c, "+").concat(u)
return this.he(c)
}
rt(t) {
var n = this.qe(), r = n["num"], i = n["tokenVal"],
c = this.a(""["concat"](t)["split"](""))["join"]("") + this.a(""["concat"](i)["split"](""))["join"](""),
u = "";
for (var s = 0; (s < c["length"]); s += r) {
var l = c["substring"](s, s + r);
u += this.a(l["split"](""))["join"]("")
}
var res = u["substring"](0, 20);
logger('倒叙处理字符返回20位', res)
return res;
}
Ke(t) {
var n = "6|5|4|3|0|1|2"["split"]("|"), o = 0;
while (1) {
switch (n[o++]) {
case "0":
(s["length"] > 1) && (f = s[0], l = s[1]["split"]("&"));
continue;
case "1":
for (var a = 0; a < l["length"]; a++) {
var c = l[a], u = c.split("=");
("t" !== u[0]) && "urlyzm" !== u[0] && "ruuid" !== u[0] && (f += "".concat(f.includes("?") ? "&" : "?").concat(c))
}
continue;
case "2":
(-1 === f.indexOf("?")) && (f += "?");
logger(`处理url后缀${t}完成返回${f}`)
return f;
case "3":
var s = t["split"]("?"), l = [];
continue;
case "4":
(0 !== f["indexOf"]("/")) && (f += "/");
continue;
case "5":
var f = t;
continue;
case "6":
if ("" === t || null == t) {
return t;
}
continue
}
break
}
}
he(t) {
let res = CryptoJS.MD5(t).toString();
logger('生成32位小写md5', t, res)
return res
}
qe() {
var e = this.Le(), n = this.Ae(e);
null === n && (n = "");
var o = n["match"]("[0-9]+");
if ((null === o)) {
o = 3;
} else {
var a = o["index"];
o = parseInt(n["substring"](a, (a + 1)), 10) + 3
}
return {
num: o, tokenVal: n
}
}
Le() {
var e = this.Ae("security-token-key");
if (!e) {
var a = this.Ae('lsmhToken');
e = a && ('lsmhToken' === a) ? 'SSOTicket' : 'dzfp-ssotoken'
}
return e
};
Ae(t) {
var n = "4|2|1|3|0"["split"]("|"), i = 0, o, l, s;
while (1) {
switch (n[i++]) {
case "0":
return null;
case "1":
o = s["indexOf"](l);
continue;
case "2":
l += "=";
continue;
case "3":
if ((-1 !== o)) {
var a = (o + l["length"]), c = s.indexOf(";", a);
(-1 === c) && (c = s.length);
var u = s.substring(a, c);
var res = unescape(u);
logger('获取token', t, '16进制解码', res)
return res;
}
continue;
case "4":
// todo: 这里获取 cookie
s = this.cookie;
l = JSON["parse"](JSON["stringify"](t));
continue
}
break
}
};
a(t) {
return t.reverse()
};
}
// let fpCrypt = new FpCrypt("oauth2_referer=dppt.hubei.chinatax.gov.cn; dzfp-ssotoken=37c347d5ab014bacb418d7756b9e7ee1; SSO_SECURITY_CHECK_TOKEN=91081171bc604d16910500c4982e74ea; c_time=12; lzkqow39189=c6edeb37685b423c8298eaa8e1b41097; DTSwUOYx7MiWN=5c199c6d5d4fda3505876d98a7e173007f4ab2ae661119adf9143257d71d06e5; lzkqow38189=1727098216617; MKls83gqduGS=e4ec10654056af2f2641b3ce60f124ee7cc607e9ac44bb8b86b9e6d5879ce1c3c7b827862a2ff46be48061c039dccddf");
// fpCrypt.handleParam('{"gjbq": "1","fpztDm": ["01","02","03","04"],"fplyDm": "0","fplxDm": [],"kprqq": "2024-09-08","kprqz": "2024-09-24","tfrqq": "2024-09-08","tfrqz": "2024-09-24","sflzfp": "","dtBz": "N","pageNumber": 1,"pageSize": 20}',
// "/szzhzz/qlfpcx/v1/queryFpjcxx?t=1727101152631")
// let handleSuffix = fpCrypt.handleSuffix("/szzhzz/qlfpcx/v1/queryFpjcxx?t=1727115438241");
// console.log(handleSuffix)
module.exports = FpCrypt