38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
# -*- 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())
|