71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
"""测试后端服务状态"""
|
|
import requests
|
|
import json
|
|
|
|
print("=" * 60)
|
|
print("后端服务状态检查")
|
|
print("=" * 60)
|
|
|
|
# 测试 PHP 后端
|
|
print("\n1. 测试 PHP 后端 (http://127.0.0.1:8080)")
|
|
print("-" * 60)
|
|
try:
|
|
response = requests.get("http://127.0.0.1:8080", timeout=3)
|
|
print(f"✓ PHP 后端正常运行")
|
|
print(f" 状态码: {response.status_code}")
|
|
except requests.exceptions.ConnectionError:
|
|
print("✗ PHP 后端未启动或无法连接")
|
|
print(" 请使用 phpstudy 启动 Apache 服务")
|
|
except Exception as e:
|
|
print(f"✗ 连接错误: {e}")
|
|
|
|
# 测试 Python 后端
|
|
print("\n2. 测试 Python 后端 (http://127.0.0.1:8000)")
|
|
print("-" * 60)
|
|
try:
|
|
response = requests.get("http://127.0.0.1:8000/docs", timeout=3)
|
|
print(f"✓ Python 后端正常运行")
|
|
print(f" 状态码: {response.status_code}")
|
|
except requests.exceptions.ConnectionError:
|
|
print("✗ Python 后端未启动")
|
|
print(" 请运行: python -m uvicorn lover.main:app --reload --host 127.0.0.1 --port 8000")
|
|
except Exception as e:
|
|
print(f"✗ 连接错误: {e}")
|
|
|
|
# 测试登录接口
|
|
print("\n3. 测试登录接口")
|
|
print("-" * 60)
|
|
test_data = {
|
|
"mobile": "13758924481",
|
|
"password": "123456",
|
|
"captcha": "223344"
|
|
}
|
|
print(f"测试数据: {json.dumps(test_data, ensure_ascii=False)}")
|
|
|
|
try:
|
|
response = requests.post(
|
|
"http://127.0.0.1:8080/api/user/mobilelogin",
|
|
json=test_data,
|
|
headers={
|
|
"Content-Type": "application/json",
|
|
"sid": "2"
|
|
},
|
|
timeout=5
|
|
)
|
|
print(f"状态码: {response.status_code}")
|
|
print(f"响应: {json.dumps(response.json(), ensure_ascii=False, indent=2)}")
|
|
except requests.exceptions.ConnectionError:
|
|
print("✗ 无法连接到登录接口")
|
|
print(" PHP 后端可能未正确配置")
|
|
except Exception as e:
|
|
print(f"✗ 请求错误: {e}")
|
|
|
|
print("\n" + "=" * 60)
|
|
print("检查完成")
|
|
print("=" * 60)
|
|
|
|
print("\n建议:")
|
|
print("1. 如果 PHP 后端未启动,请使用 phpstudy 启动 Apache")
|
|
print("2. 如果登录接口返回错误,检查数据库中是否有该用户")
|
|
print("3. 如果需要创建测试用户,可以在数据库中手动添加")
|