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.
326 lines
12 KiB
326 lines
12 KiB
const CryptoJS = require('crypto-js'); |
|
|
|
logger = console.info; |
|
|
|
class FpCrypt { |
|
cookie = ""; |
|
publicKey = { |
|
publicKey: "", tokenKey: "" |
|
}; |
|
|
|
constructor(cookies) { |
|
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; |
|
// while (1) { |
|
// switch (a[c++]) { |
|
// case "0": |
|
// // if (h && ("" !== h) && "1" !== h && (1 !== h)) |
|
// // ("2" === h) && (s = function (t, e, r) { |
|
// // var a = t; |
|
// // if (t['indexOf']('urlyzm=') > -1) return t; |
|
// // if (t = this.He(t), r) { |
|
// // var c = t["indexOf"]("?"), u = t['substring']((c + 1)), s = u['indexOf']('ruuid='), |
|
// // l = u['substring'](s + 6); |
|
// // l = l['substring'](0, l['indexOf']("&")); |
|
// // var f = t['substring'](0, c), |
|
// // d = t["indexOf"]("?") > -1 ? t['substring'](0, t['indexOf']("?")) : t; |
|
// // t = Ye(u, d); |
|
// // t = ""["concat"](f, '?urlyzm=')['concat'](encodeURIComponent(t), '&ruuid=')['concat'](l) |
|
// // } |
|
// // return t |
|
// // }(s, 0, f)); |
|
// // else |
|
// s = this.He(s, d, 0, e) |
|
// if (p) { |
|
// var u = (new Date)['valueOf'](); |
|
// s += '&urls='['concat'](u) |
|
// } |
|
// logger(`处理url后缀${t} 完成返回${s}`) |
|
// return s; |
|
// case "1": |
|
// if (!t) return t; |
|
// continue; |
|
// case "2": |
|
// s = t; |
|
// l = this.Re(); |
|
// f = l['publicKey']; |
|
// d = l['tokenKey']; |
|
// h = l['urlType']; |
|
// p = l['urlYzm']; |
|
// continue; |
|
// case "3": |
|
// logger(`处理url后缀${t} 完成返回${s}`) |
|
// return s; |
|
// case "4": |
|
// if (t['indexOf']('cssSecurity/v1/getPublicKey') > -1) return t; |
|
// continue |
|
// } |
|
// break |
|
// } |
|
} |
|
|
|
/** |
|
* 处理 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; |
|
if ((d >= 0) && (d <= 50)) { |
|
l = this.Qs(f) |
|
} |
|
// (d >= 0) && (d <= 50) ? l = this.Qs(f) : (d >= 51) && d <= 100 && (l = function (t, e) { |
|
// // TODO: 偷懒 |
|
// return null; |
|
// // var n = c; |
|
// // if ('PwUOp' === 'PwUOp') { |
|
// // for (var r = this.qe(), o = r[n(3123)], s = r[n(2049)], l = i[n(5528)](i[n(2694)](a, ""["concat"](t)[n(619)](""))["join"](""), a(""["concat"](s)[n(619)](""))[n(739)]("")), f = "", d = 0; i[n(3114)](d, l[n(6147)]); d += o) { |
|
// // var h = l[n(6370)](d, d + o); |
|
// // f += i[n(2694)](a, h[n(619)](""))[n(739)]("") |
|
// // } |
|
// // var p = "", v = e; |
|
// // if (e) for (var b = 0; i[n(3114)](b, v[n(6147)]); b += o) { |
|
// // var g = v["substring"](b, i[n(5528)](b, o)); |
|
// // p += a(g["split"](""))["join"]("") |
|
// // } else p = i[n(5434)]; |
|
// // return p = i[n(2694)](a, ""['concat'](p)[n(619)](""))[n(739)](""), i[n(5528)](i[n(5528)](i[n(5528)](f[n(6370)](0, 5), p[n(6370)](5, 10)), f[n(6370)](15, 20)), p["substring"](20, 25)) |
|
// // } |
|
// // for (var m = _0x34c263[_0x383cd9], y = u[n(5694)](_0x30e1f9, 1); y < _0x181e94["length"] && u[n(4847)](m, _0x4913da);) m *= _0x12c36b[y++]; |
|
// // for (m = _0x469f9b[n(1024)](m); u["tKkZS"](_0x4bdcfe, y);) if (u[n(5152)](u["wSsxC"](m, _0x4de108[_0x8b459++]), 0)) return !1 |
|
// }(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 (i[c(2228)](i[c(315)], c(6715))) _0x2cc2bd("crypto"); else { |
|
// var g = b["charAt"](0)['toUpperCase'](); |
|
// b['length'] > 1 && (g += b['slice'](1)); |
|
// var m = o[b]; |
|
// i[c(2228)](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)) |
|
}; |
|
|
|
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 |