import json
import subprocess
from functools import partial
import requests
subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import execjs
with open('sm2Utils.js', 'r', encoding='utf8') as fr:
str_data = fr.read()
js_code = execjs.compile(str_data)
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Language": "zh-CN,zh;q=0.9",
"Content-Type": "application/json;charset=UTF-8",
"Origin": "Origin",
"Referer": "Referer",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
"encrypt": "1"
}
url = "url "
params = {
"foreSessionClusterIntercept": "true"
}
post_data = {"token": "Epoint_WebSerivce_**##0601",
"params": {"categuids": "4bcbbec7-2428-403a-8eed-b0db5c0e01a5", "titlename": "", "currpage": 0,
"pagesize": 10}}
print('encrypt data: ', json.dumps(post_data, separators=(',', ':')))
data = js_code.call('encrypt', json.dumps(post_data, separators=(',', ':')))
print('encrypt result: ', data)
response = requests.post(url, headers=headers, params=params, data=data, verify=False)
print('request result: ', response.text)
decrypt_result = js_code.call('decrypt', response.text)
print('decrypt result: ', decrypt_result)