| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- # -*- coding: utf-8 -*-
- import httpx
- class GotifyNotifier:
- def __init__(self, title, message):
- self.gotify_url = 'https://gotify.erhe.top'
- self.app_token = 'Aw7XKE2Ppk7Dgwk'
- self.title = title
- self.message = message
- def send_message(self):
- # 构建POST请求的headers
- headers = {
- 'Content-Type': 'application/json'
- }
- # 构建POST请求的body
- body = {
- 'title': self.title,
- 'message': self.message
- }
- # 发送POST请求
- with httpx.Client() as client:
- response = client.post(
- url=f"{self.gotify_url}/message?token={self.app_token}",
- headers=headers,
- json=body
- )
- # 或者可以使用 curl
- # curl -k "https://gotify.erhe.top/message?token=A0Xg6ZE5946iBYg" -F "title=测试发送信息" -F "message=假装有信息,测试发送" -F "priority=5"
- # 检查响应状态码
- if response.status_code == 200:
- print('Gotify Message sent successfully!')
- else:
- print('Failed to send message:', response.text)
|