const {jsdomFromText, jsdomFromUrl, browser} = require('sdenv'); const path = require("path"); const fs = require("fs"); const {Script} = require("vm"); const baseUrl = "https://tpass.hebei.chinatax.gov.cn:8443/" const files = { html: path.resolve('../public/hubei/index.html'), js: path.resolve('../public/hubei/5PXGXoOF7eGJ.ed63b8f.js'), ts: path.resolve('../public/hubei/ts.json'), } function getFile(name) { const filepath = files[name]; if (!filepath) throw new Error(`getFile: ${name}错误`); if (!fs.existsSync(filepath)) throw new Error(`文件${filepath}不存在,请使用rs-reverse工具先获取文件`); return fs.readFileSync(filepath); } function loadPages() { const htmlText = getFile('html'); const jsText = getFile('js'); let file = getFile('ts'); let url = `${baseUrl}sys-api/v1.0/auth/oauth2/getPublicKey`; const [jsDom, cookieJar] = jsdomFromText({ url: url, referrer: url, contentType: "text/html", runScripts: "outside-only", }) const dom = jsDom(htmlText); window = dom.window window.$_ts = JSON.parse(file.toString()); window.onbeforeunload = async (url) => { const cookies = cookieJar.getCookieStringSync(baseUrl); console.debug(`${url} 生成cookie:`, cookies); window.close(); } new Script(jsText.toString()).runInContext(dom.getInternalVMContext()); browser(dom.window, 'chrome'); console.log(111) } let promise = loadPages() module.exports = promise