38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import requests
|
|
from config import API_KEY, API_URL
|
|
|
|
class MessageSender:
|
|
def __init__(self):
|
|
self.api_url = API_URL
|
|
self.api_key = API_KEY
|
|
|
|
def send_message(self, content: str, title: str = "POE 通知") -> bool:
|
|
"""
|
|
发送消息
|
|
:param content: 消息内容
|
|
:param title: 消息标题
|
|
:return: 是否发送成功
|
|
"""
|
|
try:
|
|
# 完全使用与示例代码相同的结构
|
|
response = requests.post(
|
|
self.api_url,
|
|
headers={
|
|
"X-API-Key": self.api_key,
|
|
"Content-Type": "application/json"
|
|
},
|
|
json={
|
|
"content": content,
|
|
"title": title
|
|
}
|
|
)
|
|
|
|
print(f"\n发送消息结果:")
|
|
print(f"状态码: {response.status_code}")
|
|
print(f"响应: {response.json()}")
|
|
|
|
return response.status_code == 200
|
|
|
|
except Exception as e:
|
|
print(f"发送消息失败: {str(e)}")
|
|
return False |