import hashlib
import requests
import time
def sign(params):
"""
生成参数签名
Args:
params (dict): 待签名的参数字典
Returns:
str: 返回生成的签名字符串
"""
sorted_params = sorted(params.items())
temp = ''
for key, value in sorted_params:
temp += '{}{}'.format(key, value)
return encode(temp).upper()
def encode(data):
"""
使用 SHA1 算法对数据进行编码
Args:
data (str): 待编码的数据
Returns:
str: 返回编码后的字符串
"""
return hashlib.sha1(data.encode()).hexdigest()
url = "https://zdjk.sthjt.gxzf.gov.cn:1000/amOnline/app/was/baseroute/requestRoute!databack.page"
headers = {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,i"
"mage/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"accept-language": "zh-CN,zh;q=0.9",
"cache-control": "no-cache",
"pragma": "no-cache",
"sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "none",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1",
"Content-Type": "application/x-www-form-urlencoded",
"accessToken": "FC7333AF-4D89-4078-BA90- 4F533ED62806",
"Referer": "https://zdjk.sthjt.gxzf.gov.cn:1000/amOnline/zdjk-company-base/login",
"from": "out",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Apple"
"WebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.289 Safari/537.36"
}
params = {
"_ts": int(time.time()),
}
params2 = {
"start_time": "2024-05-16 14:00:00",
"end_time": "2024-05-16 15:00:00",
"mpId": "6e87c3b5156cd2d15as8797857e730efb",
"type": "1",
"method": "getAutoHourAir"
}
params["sign"] = sign(params)
params.update(params2)
response = requests.post(url, headers=headers, data=params)
print(response.text)