import json import requests import time import sign_key import multiprocessing def send_post(): url = "http://192.168.0.99:7081" # 应用ID和私钥 app_id = "202304211098921821299802112" with open('private_key.pem', 'rb') as f: key = f.read() app_private_key = key # 请求参数 params = { "charset": "utf-8", "biz_content": '{"attendancePeriodName":"","endTime":"2023-12-08 10:34:00","startTime":"2022-11-08 10:34:00",' '"tenantId":"30","userCode":"20180219","userId":""}', "method": "dorm.selfChoice.personAttendanceRecordList", "format": "json", "app_id": app_id, "sign_type": "RSA2", "version": "1.0", } # 时间戳 timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) params["timestamp"] = timestamp # 生成待签名字符串 data = "&".join([f"{key}={params[key]}" for key in sorted(params)]) # 计算签名 private_key = sign_key.rsa256_sign(data, app_private_key, 'utf-8') sign = private_key # 添加签名,发送请求 params["sign"] = sign print(sign) start_time = time.time() response = requests.post(url, data=params) end_time = time.time() print("函数调用【{}】耗时 【{}】秒".format(response, end_time - start_time)) print(response.text) if response.status_code == requests.codes.ok: data = json.loads(response.text) # 处理返回的数据 else: print(f"请求失败,错误码:{response.status_code}") print(f"错误信息:{response.text}") if __name__ == "__main__": processes = [] for i in range(300): processes.append(multiprocessing.Process(target=send_post())) for i in range(300): processes[i].start() for i in range(300): processes[i].join()
RSA2 验签后接口调用
最新推荐文章于 2024-08-31 10:53:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)