Spaces:
Runtime error
Runtime error
Download debug_sign.py from CLASSZhao2653/yahoo_2_test: direct link, hf CLI and curl.
- Browser
- Download file 3.08 kB
-
https://huggingface.co/spaces/CLASSZhao2653/yahoo_2_test/resolve/main/debug_sign.py
- Command line
-
hf download hf://spaces/CLASSZhao2653/yahoo_2_test/debug_sign.py
-
curl -L -o debug_sign.py https://huggingface.co/spaces/CLASSZhao2653/yahoo_2_test/resolve/main/debug_sign.py
3.08 kB
| """ | |
| 签名深度诊断脚本 - 1秒揪出根本原因 | |
| """ | |
| import requests | |
| import json | |
| import urllib3 | |
| from brm_api import BrmApi | |
| from config_manager import load_accounts | |
| from brm_cipher import CIPHER | |
| urllib3.disable_warnings() | |
| # 1. 读取当前配置的账号 | |
| accs = load_accounts() | |
| acc_name = list(accs.keys())[0] | |
| cred = accs[acc_name] | |
| api = BrmApi(cred["authorization"], cred["tokenid"]) | |
| print("=" * 60) | |
| print(f"👤 当前测试账号: {acc_name}") | |
| # 2. 检查 Python SM4 加密输出与抓包密文的比对 | |
| # 抓包 78_Full.txt 中真实的坐标是 43.821837 和 87.578650 | |
| test_lat = "43.821837" | |
| test_lng = "87.578650" | |
| py_enc_lat = CIPHER.encrypt_ecb_base64(test_lat) | |
| py_enc_lng = CIPHER.encrypt_ecb_base64(test_lng) | |
| py_enc_sign = CIPHER.encrypt_ecb_base64(f"{test_lat}&cxd&{test_lng}") | |
| # 抓包 43_Full.txt 里的真实基准密文 | |
| capture_lat = "RfWoZICjh+lBE3AzKDKE3Q==" | |
| capture_lng = "6gGRzcUDayrD5YsTKuaEcQ==" | |
| capture_sign = "GAbM4M/Qcuj7e8JYMbvAaf2XsTkBRS5RJ/zxAd5H5u0=" | |
| print("\n【诊断 1:SM4 算法输出比对】") | |
| print(f"抓包纬度基准密文: {capture_lat}") | |
| print(f"Python计算的密文: {py_enc_lat}") | |
| print(f"--> 是否完全吻合: {'✅ 吻合!' if py_enc_lat == capture_lat else '❌ 不吻合!'}") | |
| print(f"\n抓包签名基准密文: {capture_sign}") | |
| print(f"Python计算的签名: {py_enc_sign}") | |
| print(f"--> 是否完全吻合: {'✅ 吻合!' if py_enc_sign == capture_sign else '❌ 不吻合!'}") | |
| # 3. 发起一次直连抓包测试 | |
| print("\n【诊断 2:直接重放抓包基准参数测试服务端响应】") | |
| url = f"{api.BASE_URL}/brm_applet/index/search" | |
| params_capture = { | |
| "activityName": "", | |
| "platform": "", | |
| "sortBy": "1", | |
| "classifyId": "", | |
| "pagesize": "10", | |
| "current": "1", | |
| "now": "0", | |
| "pagePvId": "", | |
| "cityName": "乌鲁木齐市", | |
| "latitude": capture_lat, | |
| "longitude": capture_lng, | |
| "sign": capture_sign | |
| } | |
| try: | |
| r1 = api.session.get(url, headers=api.headers, params=params_capture, timeout=5, verify=False).json() | |
| print(f"👉 抓包密文请求结果: code={r1.get('code')}, message={r1.get('message')}") | |
| if r1.get('code') == 200: | |
| print(f" 🎉 成功拉取到 {len(r1.get('data', {}).get('resultList', []))} 家店铺!") | |
| except Exception as e: | |
| print(f"👉 请求异常: {e}") | |
| # 4. 发起 Python 实时算签测试 | |
| print("\n【诊断 3:使用 Python 实时加密的密文请求测试】") | |
| params_python = params_capture.copy() | |
| params_python["latitude"] = py_enc_lat | |
| params_python["longitude"] = py_enc_lng | |
| params_python["sign"] = py_enc_sign | |
| try: | |
| r2 = api.session.get(url, headers=api.headers, params=params_python, timeout=5, verify=False).json() | |
| print(f"👉 Python密文请求结果: code={r2.get('code')}, message={r2.get('message')}") | |
| if r2.get('code') == 200: | |
| print(f" 🎉 成功拉取到 {len(r2.get('data', {}).get('resultList', []))} 家店铺!") | |
| except Exception as e: | |
| print(f"👉 请求异常: {e}") | |
| print("=" * 60) |