"""测试正式服务器 Mock 登录 POST 接口"""
import urllib.request, ssl, json

ctx = ssl.create_default_context()

# 测试 1: Mock 登录
url = "https://itsupport.servyou.com.cn/api/h5/mock-login"
data = json.dumps({"employee_id": "admin001"}).encode()

req = urllib.request.Request(url, data=data, method="POST")
req.add_header("Content-Type", "application/json")

print("=== 测试1: Mock登录 POST /api/h5/mock-login ===")
try:
    resp = urllib.request.urlopen(req, context=ctx, timeout=10)
    print(f"Status: {resp.status}")
    body = resp.read().decode()
    print(f"Body: {body}")
    result = json.loads(body)
    print(f"Code: {result.get('code')}")
    print(f"Message: {result.get('message')}")
    if result.get("data"):
        print(f"Data keys: {list(result['data'].keys())}")
except urllib.request.HTTPError as e:
    print(f"Status: {e.code}")
    print(f"Body: {e.read().decode()}")

# 测试 2: Admin dashboard (需要auth, 预期401)
print("\n=== 测试2: Admin Dashboard GET /api/admin/dashboard/overview ===")
url2 = "https://itsupport.servyou.com.cn/api/admin/dashboard/overview"
req2 = urllib.request.Request(url2, method="GET")
try:
    resp = urllib.request.urlopen(req2, context=ctx, timeout=10)
    print(f"Status: {resp.status}")
    print(f"Body: {resp.read().decode()}")
except urllib.request.HTTPError as e:
    print(f"Status: {e.code}")
    print(f"Body: {e.read().decode()}")

# 测试 3: Admin agents list (需要auth)
print("\n=== 测试3: Admin Agents GET /api/admin/agents ===")
url3 = "https://itsupport.servyou.com.cn/api/admin/agents"
req3 = urllib.request.Request(url3, method="GET")
try:
    resp = urllib.request.urlopen(req3, context=ctx, timeout=10)
    print(f"Status: {resp.status}")
    print(f"Body: {resp.read().decode()}")
except urllib.request.HTTPError as e:
    print(f"Status: {e.code}")
    print(f"Body: {e.read().decode()}")
