You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

49 lines
1.9 KiB

# -*- coding: utf-8 -*-
"""MISSING 4 补录前置实测:region/list + region/level 真实响应摘录,供 .bru 示例值取材。"""
import io
import json
import sys
import requests
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
BASE = "http://localhost:8080"
tr = requests.get(BASE + "/api/auth/debug/token",
params={"userId": "739564171091247104"}, timeout=15).json()
assert tr.get("code") == 0, "debug token 失败: %s" % tr
H = {"Authorization": "Bearer " + tr["data"]}
out = {}
# 1) level=1 省级
r1 = requests.get(BASE + "/api/rule/region/level", params={"level": 1}, headers=H, timeout=10).json()
out["level1"] = r1
print("level=1 ->", r1.get("code"), "rows:", len(r1.get("data") or []))
if r1.get("data"):
print(" 首行:", json.dumps(r1["data"][0], ensure_ascii=False))
# 2) list 无参(应同省级)
r2 = requests.get(BASE + "/api/rule/region/list", headers=H, timeout=10).json()
out["list_root"] = r2
print("list 无参 ->", r2.get("code"), "rows:", len(r2.get("data") or []))
if r2.get("data"):
print(" 首行:", json.dumps(r2["data"][0], ensure_ascii=False))
# 3) list?parentId=<首省id> 市级
if r1.get("data"):
pid = r1["data"][0]["id"]
r3 = requests.get(BASE + "/api/rule/region/list", params={"parentId": pid}, headers=H, timeout=10).json()
out["list_children"] = r3
print("list?parentId=%s ->" % pid, r3.get("code"), "rows:", len(r3.get("data") or []))
if r3.get("data"):
print(" 首行:", json.dumps(r3["data"][0], ensure_ascii=False))
# 4) level=2 市级交叉
r4 = requests.get(BASE + "/api/rule/region/level", params={"level": 2}, headers=H, timeout=10).json()
out["level2"] = r4
print("level=2 ->", r4.get("code"), "rows:", len(r4.get("data") or []))
with open(".scratch/auth-perms/m4-region-live.json", "w", encoding="utf-8") as f:
json.dump(out, f, ensure_ascii=False, indent=2)
print("saved -> .scratch/auth-perms/m4-region-live.json")