116 lines
3.6 KiB
Python
116 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
测试换装 API 返回的图片 URL
|
||
"""
|
||
import requests
|
||
import json
|
||
|
||
# API 地址
|
||
API_URL = "http://192.168.1.164:30101/outfit/mall"
|
||
|
||
# 测试 token(需要替换为实际的 token)
|
||
# 如果没有 token,可以使用 X-User-Id 调试
|
||
headers = {
|
||
"X-User-Id": "70" # 使用调试用户 ID
|
||
}
|
||
|
||
print("=" * 70)
|
||
print(" 测试换装商城 API")
|
||
print("=" * 70)
|
||
print()
|
||
print(f"API 地址: {API_URL}")
|
||
print(f"请求头: {headers}")
|
||
print()
|
||
|
||
try:
|
||
response = requests.get(API_URL, headers=headers, timeout=10)
|
||
|
||
print(f"状态码: {response.status_code}")
|
||
print()
|
||
|
||
if response.status_code == 200:
|
||
data = response.json()
|
||
|
||
print("=" * 70)
|
||
print(" API 响应")
|
||
print("=" * 70)
|
||
print()
|
||
print(f"Code: {data.get('code')}")
|
||
print(f"Message: {data.get('msg')}")
|
||
print()
|
||
|
||
if data.get('code') == 1 and 'data' in data:
|
||
outfit_data = data['data']
|
||
items = outfit_data.get('items', [])
|
||
|
||
print(f"服装数量: {len(items)}")
|
||
print(f"已拥有: {len(outfit_data.get('owned_outfit_ids', []))}")
|
||
print(f"金币余额: {outfit_data.get('balance', 0)}")
|
||
print()
|
||
|
||
if items:
|
||
print("=" * 70)
|
||
print(" 前 5 件服装")
|
||
print("=" * 70)
|
||
print()
|
||
|
||
for idx, item in enumerate(items[:5], 1):
|
||
print(f"[{idx}] {item.get('name')}")
|
||
print(f" 分类: {item.get('category')}")
|
||
print(f" 性别: {item.get('gender')}")
|
||
print(f" 价格: {item.get('price_gold')} 金币")
|
||
print(f" 图片: {item.get('image_url')}")
|
||
print()
|
||
|
||
# 测试图片 URL 是否可访问
|
||
img_url = item.get('image_url')
|
||
if img_url:
|
||
try:
|
||
img_response = requests.head(img_url, timeout=5)
|
||
if img_response.status_code == 200:
|
||
print(f" ✓ 图片可访问")
|
||
else:
|
||
print(f" ✗ 图片无法访问 (状态码: {img_response.status_code})")
|
||
except Exception as e:
|
||
print(f" ✗ 图片访问失败: {e}")
|
||
print()
|
||
else:
|
||
print("⚠️ 没有找到服装数据")
|
||
print()
|
||
print("可能的原因:")
|
||
print("1. 数据库中没有数据")
|
||
print("2. 查询条件不匹配(性别、状态等)")
|
||
print()
|
||
else:
|
||
print(f"❌ API 返回错误: {data.get('msg')}")
|
||
print()
|
||
else:
|
||
print(f"❌ HTTP 错误: {response.status_code}")
|
||
print(f"响应内容: {response.text[:500]}")
|
||
print()
|
||
|
||
except requests.exceptions.Timeout:
|
||
print("❌ 请求超时")
|
||
print()
|
||
print("请检查:")
|
||
print("1. Python 服务是否运行")
|
||
print("2. 端口 30101 是否正确")
|
||
print()
|
||
except requests.exceptions.ConnectionError:
|
||
print("❌ 连接失败")
|
||
print()
|
||
print("请检查:")
|
||
print("1. Python 服务是否运行")
|
||
print("2. 地址是否正确: http://192.168.1.164:30101")
|
||
print()
|
||
except Exception as e:
|
||
print(f"❌ 发生错误: {e}")
|
||
print()
|
||
import traceback
|
||
traceback.print_exc()
|
||
|
||
print("=" * 70)
|
||
print(" 测试完成")
|
||
print("=" * 70)
|