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.
 
 

146 lines
6.4 KiB

const {jsdomFromText, browser} = require("sdenv");
const {Script} = require("node:vm");
const fs = require("node:fs");
const FpCrypt = require("../../routes/service/static/fp/fp-crypt");
var baseUrl = 'https://dppt.hubei.chinatax.gov.cn:8443'
// TODO 需要文件内的 meta name="_y_ds" content 标签内容
var html = fs.readFileSync('./invoice-business.html', 'utf8').toString();
let js = fs.readFileSync('./chunk-npjg4qgmmrfrjl3r.js', 'utf8').toString();
// TODO:用户登陆token 测试时需要替换
var loginCookieStr = "oauth2_referer=dppt.hubei.chinatax.gov.cn; dzfp-ssotoken=37c347d5ab014bacb418d7756b9e7ee1; SSO_SECURITY_CHECK_TOKEN=91081171bc604d16910500c4982e74ea; c_time=12; lzkqow39189=9b8cabc2e1194d5b93f6ef9f46004612; DTSwUOYx7MiWN=f2045053f3ad56575c946fd47a49632842e4f7850c561ccaddecc28de91fa92e; lzkqow38189=1727122084863; MKls83gqduGS=d3ba2a8eb4284ff70c7c0fff4a9dcbdd85c92b046de5b0045c3d61eecc23acb1f48a82f31cb672cd93e47b163696b0d9"
var urlPath = `/szzhzz/qlfpcx/v1/queryFpjcxx?t=${new Date().getTime()}`
// var urlPath = `/szzhzz/qlfpcx/v1/queryFpjcxx`
// TODO:如果有 param 加密后得到 enParam
var param = '{"gjbq":"1","fpztDm":["01","02","03","04"],"fplyDm":"0","fplxDm":[],"kprqq":"2024-09-09","kprqz":"2024-09-25","tfrqq":"2024-09-09","tfrqz":"2024-09-25","sflzfp":"","dtBz":"N","pageNumber":1,"pageSize":20}';
let fpCrypt = new FpCrypt(loginCookieStr, {
"publicKey": "MIGf1MA0GCSqGSI2b03DQEBAQUAA4GNADCBiQKBgQDzT/x0AfuV0vtyMKvPWDNMKZbDo8uBqouTYAF8X8uS//z/HqpXBC07CLpnfpOoijwI/zbiPD9RTaEB3PaukaDYxBxE/yBFSByBH3wh5XcIOxi8lpqMBEKun+AjAr91tXUnjkKioI3u7S2hSxh5HgWTVXm1OHAMPW/+w2nmA0Hk2QIDAQAB",
"tokenKey": "f84df3d0021d4c09b270c5d17d86535f",
});
let handleParam = fpCrypt.handleParam(param, urlPath);
var enParam = JSON.stringify({'Jmbw': handleParam["enVal"]});
// headers['security-mes-key'] = $e["enMesKey"]
let handleSuffix = fpCrypt.handleSuffix(urlPath);
get_los(handleSuffix, enParam);
// fpService = new FpService()
// get_los_test_service()
// async function get_los_test_service() {
// let los = await fpService.get_los(url, enParam, html, loginCookieStr);
// var getPublicKey = await fetch(`${baseUrl + los.hurl}`, {
// "headers": {
// "accept": "*/*",
// "accept-language": "zh-CN,zh;q=0.9",
// "cache-control": "no-cache",
// "content-type": "text/plain;charset=UTF-8",
// "lzkqow23819": `${los.hd}`,
// // "bluewareguid": "d8fd3f2be1d8f629",
// // "cache-contro": "no-store",
// // "connection": "keep-alive",
// // "content-length": "421",
// // "date": "Mon, 23 Sep 2024 06:38:44 GMT",
// // "pragma": "no-cache",
// // "server": "Unknown",
// // "x-content-options": "nosniff",
// // "x-proxy-by": "Tif-accessgate",
// // "x-xss-protection": "1;mode=block",
// // "pragma": "no-cache",
// // "sec-ch-ua": "\"Not)A;Brand\";v=\"99\", \"Google Chrome\";v=\"127\", \"Chromium\";v=\"127\"",
// // "sec-ch-ua-mobile": "?0",
// // "sec-ch-ua-platform": "\"Linux\"",
// // "sec-fetch-dest": "empty",
// // "sec-fetch-mode": "cors",
// // "sec-fetch-site": "same-origin",
// "sso_security_check_token": "e133ba1f6f124599af5fa5262e1adf02",
// "x-requested-with": "XMLHttpRequest",
// "cookie": cookieJar.getCookieStringSync(baseUrl),
// // "Referer": "https://dppt.hubei.chinatax.gov.cn:8443/invoice-business?ruuid=1726970597058",
// "Referrer-Policy": "strict-origin-when-cross-origin"
// },
// "body": "",
// "method": "POST"
// });
//
//
// console.log('测试getPublicKey请求', await getPublicKey.json())
// }
async function get_los(url, param) {
console.time('js执行时长')
const [jsDom, cookieJar] = jsdomFromText({
url: `${baseUrl}/invoice-query/invoice-query`,
referrer: baseUrl,
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
contentType: "text/html",
runScripts: "outside-only", // runScripts: 'dangerously'/'outside-only'
})
// 加载dom
let dom = await jsDom(html);
const window = dom.window
// 设置 cookie
for (let cookie of loginCookieStr.trim().split("; ")) {
cookieJar.setCookieSync(cookie, baseUrl);
}
browser(window, 'chrome');
// 加载js
let script = new Script(js);
let internalVMContext = dom.getInternalVMContext();
// 执行 js
script.runInContext(internalVMContext, {timeout: 1000});
if (window.$dunm.$byno) {
window.$dunm.$byno();
}
let los = window[window["_d_ts"]](url, param);
console.log('js执行完成,返回结果 ', los)
// 关闭
dom.window.close()
console.timeEnd('js执行时长')
console.log(cookieJar.getCookieStringSync(baseUrl))
var getPublicKey = await fetch(`${baseUrl + los.hurl}`, {
"headers": {
"security-mes-key": "",
"accept": "application/json, text/plain, */*",
"accept-language": "zh-CN,zh;q=0.9",
"accept-encoding": "gzip, deflate, br, zstd",
"nsrsbh": "91420112MA49HA6G1W",
// "origin": "https://dppt.hubei.chinatax.gov.cn:8443",
// "cache-control": "no-cache",
"content-type": "application/json",
"lzkqow23819": `${los.hd}`,
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
// "x-api-type": "xhr",
"sso_security_check_token": "91081171bc604d16910500c4982e74ea",
"x-requested-with": "XMLHttpRequest",
"cookie": cookieJar.getCookieStringSync(baseUrl),
// "Referer": "https://dppt.hubei.chinatax.gov.cn:8443/invoice-business?ruuid=1726970597058",
"Referrer-Policy": "strict-origin-when-cross-origin",
// "x-b3-sampled":"1",
// "x-b3-spanid": "c850e3c1a85ee988",
// "x-b3-traceid": "c850e3c1a85ee988",
// "x-tsf-client-timestamp": `${new Date().getTime()}000`
},
"body": `${los.bd}`,
"method": "POST"
});
let newVar = await getPublicKey.json();
console.log('测试请求', newVar)
if (newVar['data']) {
console.log(newVar['data'])
}
}