# -*- coding: utf-8 -*- """probe_test_env.py — 测试环境连通性探测(只读,不造数)""" import io, sys sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') import requests BASE = 'http://ai.itc.vip/crm-api' ADMIN = '739564171091247104' print(f'== 1. ping(免鉴权端点)==') try: r = requests.get(f'{BASE}/api/customer/ping', timeout=10) print(f' GET /api/customer/ping → HTTP {r.status_code} {r.text[:120]}') except Exception as e: print(f' x 连接失败: {e}'); sys.exit(1) print(f'== 2. debug token(verify profile 探测)==') try: r = requests.get(f'{BASE}/api/auth/debug/token', params={'userId': ADMIN}, timeout=10) print(f' GET /api/auth/debug/token → HTTP {r.status_code}') body = {} try: body = r.json() except Exception: print(f' 响应非 JSON: {r.text[:120]}') tok = body.get('data') if isinstance(body, dict) else None tok = tok.get('token') if isinstance(tok, dict) else tok if r.status_code == 200 and tok: print(f' token 前缀: {str(tok)[:24]}...(verify profile 已激活)') H = {'Authorization': f'Bearer {tok}'} print(f'== 3. 数据状态(mine/pool/字典)==') m = requests.post(f'{BASE}/api/customer/workspace/mine/page', data={'current': 1, 'size': 3}, headers=H, timeout=15).json() p = requests.post(f'{BASE}/api/customer/workspace/pool/page', data={'current': 1, 'size': 3}, headers=H, timeout=15).json() mc, pc = (m.get('data') or {}).get('total'), (p.get('data') or {}).get('total') print(f' mine total={mc} pool total={pc} (code={m.get("code")}/{p.get("code")})') mc_rows = (m.get('data') or {}).get('content') or [] for row in mc_rows[:3]: print(f' - {row.get("customerNo")} {row.get("customerName")} owner={row.get("ownerUserNameSnapshot")}') for g in ('customer_type', 'follow_way', 'industry', 'contact_source'): d = requests.get(f'{BASE}/api/dict/item/enabled-list', params={'groupCode': g}, headers=H, timeout=10).json() items = d.get('data') or [] print(f' dict {g}: {len(items)} 项' + (' ⚠ 空' if not items else f'(首项 {items[0].get("code")})')) else: print(f' body.code={body.get("code") if isinstance(body, dict) else "-"} message={str(body.get("message"))[:100] if isinstance(body, dict) else "-"}') print(' → debug token 不可用:测试环境未带 verify profile(或端点被拦)。demo 登录将 404,需要调整启动配置。') except Exception as e: print(f' x 探测失败: {e}')