|
发表于 2024-7-29 13:11:41
|
显示全部楼层
河南省漯河市
import requests import json import time import hashlib # API 请求的 URL url = "https://mxsa.mxbc.net/api/v1/h5/marketing/secretword/confirm" # 固定的请求头信息,包括有效的 Access-Token USER_AGENT = "Mozilla/5.0 (Linux; Android 10; Pixel 3 XL Build/QPP6.190730.005) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Mobile Safari/537.36" REFERER = "https://mxsa-h5.mxbc.net/" ACCEPT_LANGUAGE = "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7" ACCESS_TOKEN = "" # Token # 固定的值,用于生成签名 FIXED_VALUE = "c274bac6493544b89d9c4f9d8d542b84" def get_current_timestamp(): """获取当前的时间戳(毫秒)""" return int(time.time() * 1000) def create_payload(marketingId, round_time, secretword, s): """生成请求的负载数据""" timestamp = get_current_timestamp() hash_string = f"marketingId={marketingId}&round={round_time}&s={s}&secretword={secretword}&stamp={timestamp}{FIXED_VALUE}" sign = hashlib.md5(hash_string.encode()).hexdigest() return json.dumps({ "marketingId": marketingId, "round": round_time, "secretword": secretword, "sign": sign, "s": s, "stamp": timestamp }) def send_request(marketingId, round_time, secretword, s): """发送 POST 请求并打印响应内容""" payload = create_payload(marketingId, round_time, secretword, s) headers = { 'User-Agent': USER_AGENT, 'Accept': "application/json, text/plain, */*", 'Content-Type': "application/json;charset=UTF-8", 'Referer': REFERER, 'Accept-Language': ACCEPT_LANGUAGE, 'Access-Token': ACCESS_TOKEN # 确保 Access-Token 被正确设置 } try: response = requests.post(url, data=payload, headers=headers) response.raise_for_status() # 检查请求是否成功 print(response.json()) # 打印响应内容 except requests.RequestException as e: print(f"请求失败: {e}") def execute_requests(num_requests, delay_ms=780): """执行指定次数的请求,每次请求之间有延迟""" for i in range(num_requests): print(f"执行请求 {i+1}/{num_requests}...") send_request("1816854086004391938", "13:00", "好一朵美丽的茉莉花", 2) time.sleep(delay_ms / 1000) # 将毫秒转换为秒 if __name__ == "__main__": print("脚本启动") execute_requests(1000) print("脚本结束") |
|