import time import jwt import requests # 认证配置 access_token = "xxxxxxx" # 页面-配置管理-项目信息-APPKEY app_id = "xxxxxx" # 页面-配置管理-项目信息-APPID username = "xxxxx" # 请替换为企微ID(非企微用户使用用户名) # JWT Header jwt_headers = { "alg": "HS256", "typ": "JWT" } # 设置token过期时间 exp = int(time.time() + 120) # 业务参数 payload = { "start": "2025-12-10 00:00:00", "end": "2025-12-20 00:00:00", "CountrySplit": 1, "countryId": -1, "aggType": "province", "excludeVpn": False, "excludeCross": False, "_country": ["中国"], "_province": ["全部"], "_city": ["综合"], "app_version": ["0.2.6.943"], "platform": 0, "netLables": [], "_scene": [], "requestid": username+"_netDelayData_openapi", "userName": "xxxxx", "exp": exp } # 生成 JWT Token jwt_token = jwt.encode(payload=payload, key=access_token, algorithm='HS256', headers=jwt_headers) # 构造请求参数 params = { 'app_id': app_id, 'username': username, 'token': jwt_token, } # 发送请求 headers = {'Content-Type': 'application/json'} # 国内环境 url = 'https://api.perfsight.qq.com/openapi/net/netDelayData' # 海外环境(新加坡) # url = 'https://api.perfsight.wetest.net/openapi/net/netDelayData' response = requests.post(url, json=params, headers=headers) # 打印返回数据 print("Status Code:", response.status_code) print("Zone Aggregate All:", response.json()["data"]["ret"]["zoneAggAll"])