|
|
@@ -0,0 +1,48 @@
|
|
|
+from fastapi import FastAPI, HTTPException
|
|
|
+import subprocess
|
|
|
+
|
|
|
+app = FastAPI()
|
|
|
+
|
|
|
+# Gotify 服务器的 URL
|
|
|
+GOTIFY_URL = "https://gotify.erhe.top"
|
|
|
+
|
|
|
+@app.get("/webhook")
|
|
|
+async def receive_checkchan_webhook(key: str, title: str, message: str):
|
|
|
+ if not key:
|
|
|
+ raise HTTPException(status_code=400, detail="Missing required parameter 'key'")
|
|
|
+ if key != 'A_SgWPLrgFAXm0d':
|
|
|
+ raise HTTPException(status_code=401, detail="Invalid API key")
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 构建命令行参数
|
|
|
+ command = [
|
|
|
+ 'curl',
|
|
|
+ '-k', # 允许不安全的 HTTPS 请求
|
|
|
+ f'{GOTIFY_URL}/message?token={key}',
|
|
|
+ '-F', f'title={title}',
|
|
|
+ '-F', f'message={message}',
|
|
|
+ '-F', 'priority=5'
|
|
|
+ ]
|
|
|
+
|
|
|
+ # 执行命令
|
|
|
+ result = subprocess.run(command, check=True, text=True, capture_output=True)
|
|
|
+ print('命令执行成功,输出:')
|
|
|
+ print(result.stdout)
|
|
|
+
|
|
|
+ if result.returncode == 0:
|
|
|
+ return {"status": "success", "message": "Message sent to Gotify"}
|
|
|
+ else:
|
|
|
+ raise HTTPException(
|
|
|
+ status_code=500, detail="Failed to send message to Gotify")
|
|
|
+ except subprocess.CalledProcessError as e:
|
|
|
+ print('命令执行失败:')
|
|
|
+ print(e.stderr)
|
|
|
+ raise HTTPException(
|
|
|
+ status_code=500, detail="Failed to send message to Gotify")
|
|
|
+ except Exception as e:
|
|
|
+ raise HTTPException(status_code=500, detail=str(e))
|
|
|
+
|
|
|
+# 运行 Uvicorn 服务器
|
|
|
+if __name__ == "__main__":
|
|
|
+ import uvicorn
|
|
|
+ uvicorn.run(app, host="0.0.0.0", port=29981)
|