File size: 3,081 Bytes
f3553a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""

签名深度诊断脚本 - 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)