You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
884 B
31 lines
884 B
# -*- 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)
|
|
|