| 12345678910111213141516171819202122232425262728293031 |
- # -*- coding: utf-8 -*-
- import httpx
- class ServerChanNotifier:
- def __init__(self, title, message):
- self.serverchan_url = 'https://sctapi.ftqq.com/SCT158272TRDcSniEdGR0TKhqhUl66LPHb.send'
- self.title = title
- self.message = message
- def send_message(self):
- # 构建POST请求的body
- body = {
- 'text': self.title,
- 'desp': self.message
- }
- # 发送POST请求
- with httpx.Client() as client:
- response = client.post(
- url=self.serverchan_url,
- headers={'Content-Type': 'application/x-www-form-urlencoded'},
- data=body
- )
- # 检查响应状态码
- if response.status_code == 200:
- print('ServerChan Message sent successfully!')
- else:
- print('Failed to send message:', response.text)
|