Files
tw/tests/test_wechat_alert.py
2026-02-27 16:03:04 +08:00

38 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""测试企微「谁在线啊」消息发送"""
import asyncio
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
async def main():
from config.config import WECHAT_WEBHOOK
import httpx
if not WECHAT_WEBHOOK:
print("未配置 WECHAT_WEBHOOK无法测试")
return
print(f"发送测试消息到企微...")
async with httpx.AsyncClient(timeout=10) as client:
resp = await client.post(WECHAT_WEBHOOK, json={
"msgtype": "text",
"text": {"content": "谁在线啊"}
})
print(f"状态码: {resp.status_code}")
print(f"响应: {resp.text}")
if resp.status_code == 200:
data = resp.json()
if data.get("errcode") == 0:
print("发送成功,请检查企微群是否收到")
else:
print(f"企微返回错误: {data}")
else:
print("发送失败")
if __name__ == "__main__":
asyncio.run(main())