# -*- coding: utf-8 -*- """冒烟三连:debug token → /me → workspace/pool/page(票 02)""" import json, sys, io, urllib.request, urllib.parse sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') BASE = 'http://localhost:8080' def req(method, path, data=None, token=None, is_json=False): url = BASE + path headers = {} body = None if data is not None: if is_json: body = json.dumps(data).encode('utf-8') headers['Content-Type'] = 'application/json; charset=utf-8' else: body = urllib.parse.urlencode(data).encode('utf-8') headers['Content-Type'] = 'application/x-www-form-urlencoded' if token: headers['Authorization'] = 'Bearer ' + token r = urllib.request.Request(url, data=body, headers=headers, method=method) try: with urllib.request.urlopen(r, timeout=20) as resp: return resp.status, json.loads(resp.read().decode('utf-8')) except urllib.error.HTTPError as e: raw = e.read().decode('utf-8', 'replace') try: return e.code, json.loads(raw) except Exception: return e.code, raw[:300] # 1) debug token st, r1 = req('GET', '/api/auth/debug/token?userId=739564171091247104') tok = r1.get('data') if isinstance(r1, dict) else None print(f'1) debug/token: http={st} code={r1.get("code") if isinstance(r1,dict) else "?"} token_len={len(tok) if tok else 0}') # 2) /me st, r2 = req('GET', '/api/auth/me', token=tok) u = r2.get('data') or {} if isinstance(r2, dict) else {} print(f'2) /me: http={st} code={r2.get("code")} user={u.get("name")} id={u.get("id")} roles={[r.get("code") for r in (u.get("roles") or [])]} dept={u.get("deptId")}') # 3) 客户端点 pool/page(真实 flat 路径 /api/customer/workspace/pool/page) st, r3 = req('POST', '/api/customer/workspace/pool/page', data={'current': 1, 'size': 5}, token=tok) d = r3.get('data') or {} if isinstance(r3, dict) else {} print(f'3) pool/page: http={st} code={r3.get("code")} total={d.get("total")} rows={len(d.get("content") or [])}') for row in (d.get('content') or [])[:3]: print(f' - {row.get("id")} {row.get("customerName")} stage={row.get("customerStage")} owner={row.get("ownerUserId")} enterPool={row.get("enterPoolTime")} oppCount={row.get("opportunityCount")}') # 附带 ping st, r4 = req('GET', '/api/customer/ping', token=tok) print(f'4) ping: http={st} data={r4.get("data") if isinstance(r4,dict) else "?"}')