"""Danding_QqPush 插件测试脚本"""
import requests
import json


def test_qqpush_api():
    """测试 QQ 推送 API"""
    
    # 配置
    base_url = "http://localhost:8080"  # NoneBot 默认端口
    token = "danding-8HkL9xQ2"  # 默认 Token
    
    # 构造请求数据
    data = {
        "group_id": 574727392,  # 替换为实际群号
        "qq": 1424473282,  # 替换为实际 QQ 号
        "text": "系统告警#数据库连接失败#请立即处理#测试消息"
    }
    
    # 发送请求
    url = f"{base_url}/danding/qqpush/{token}"
    
    print(f"正在测试 API: {url}")
    print(f"请求数据: {json.dumps(data, ensure_ascii=False, indent=2)}")
    
    try:
        response = requests.post(
            url,
            json=data,
            headers={"Content-Type": "application/json"},
            timeout=10
        )
        
        print(f"\n响应状态码: {response.status_code}")
        print(f"响应内容: {json.dumps(response.json(), ensure_ascii=False, indent=2)}")
        
        if response.status_code == 200:
            print("\n✅ 测试成功！")
        else:
            print(f"\n❌ 测试失败，状态码: {response.status_code}")
    
    except requests.exceptions.ConnectionError:
        print("\n❌ 连接失败，请确认 NoneBot 是否已启动")
    except Exception as e:
        print(f"\n❌ 测试异常: {str(e)}")


if __name__ == "__main__":
    test_qqpush_api()
