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", # accessToken在重点排污单位自动监控与基础数据库系统生成
"Referer": "https://zdjk.sthjt.gxzf.gov.cn:1000/amOnline/zdjk-company-base/login", # 替换为实际的Referer(登录界面网址)
"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", # 替换为实际的监控点id(监控点MN号,用sha-1加密)
"type": "1", # 查询类型
"method": "getAutoHourAir"
}
# 需要先只有时间戳的params生成签名,后加入其他参数
params["sign"] = sign(params)
params.update(params2)
response = requests.post(url, headers=headers, data=params)
print(response.text)
重点排污单位自动监控与基础数据库系统api python调用示例
最新推荐文章于 2025-04-22 17:54:50 发布