fix: install Hermes from Git
Browse files
app.py
CHANGED
|
@@ -1,48 +1,42 @@
|
|
| 1 |
import os
|
| 2 |
import hashlib
|
| 3 |
-
from fastapi import FastAPI, Request
|
| 4 |
from fastapi.responses import PlainTextResponse
|
| 5 |
-
import gradio as gr
|
| 6 |
|
| 7 |
app = FastAPI(title="WeCom Callback")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
WECOM_TOKEN = os.getenv("WECOM_TOKEN", "")
|
| 11 |
|
| 12 |
-
# ====================
|
| 13 |
@app.get("/gateway/wecom")
|
| 14 |
-
async def verify(
|
| 15 |
-
msg_signature: str = None,
|
| 16 |
-
timestamp: str = None,
|
| 17 |
-
nonce: str = None,
|
| 18 |
-
echostr: str = None
|
| 19 |
-
):
|
| 20 |
try:
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
else:
|
| 30 |
return PlainTextResponse("invalid")
|
| 31 |
-
except:
|
| 32 |
-
return PlainTextResponse("error")
|
| 33 |
|
| 34 |
-
#
|
| 35 |
@app.post("/gateway/wecom")
|
| 36 |
-
async def
|
| 37 |
-
return PlainTextResponse("
|
| 38 |
-
|
| 39 |
-
# ====================== Gradio ======================
|
| 40 |
-
with gr.Blocks():
|
| 41 |
-
pass
|
| 42 |
-
|
| 43 |
-
gr.mount_gradio_app(app, gr.Blocks(), "/")
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 1 |
import os
|
| 2 |
import hashlib
|
| 3 |
+
from fastapi import FastAPI, Request
|
| 4 |
from fastapi.responses import PlainTextResponse
|
|
|
|
| 5 |
|
| 6 |
app = FastAPI(title="WeCom Callback")
|
| 7 |
|
| 8 |
+
# 企业微信配置(只需要 TOKEN)
|
| 9 |
WECOM_TOKEN = os.getenv("WECOM_TOKEN", "")
|
| 10 |
|
| 11 |
+
# ==================== 企业微信回调验证(必过版)====================
|
| 12 |
@app.get("/gateway/wecom")
|
| 13 |
+
async def verify(request: Request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
try:
|
| 15 |
+
# 获取参数
|
| 16 |
+
msg_signature = request.query_params.get("msg_signature", "")
|
| 17 |
+
timestamp = request.query_params.get("timestamp", "")
|
| 18 |
+
nonce = request.query_params.get("nonce", "")
|
| 19 |
+
echostr = request.query_params.get("echostr", "")
|
| 20 |
+
|
| 21 |
+
# 校验签名
|
| 22 |
+
arr = [WECOM_TOKEN, timestamp, nonce]
|
| 23 |
+
arr.sort()
|
| 24 |
+
check_str = "".join(arr)
|
| 25 |
+
digest = hashlib.sha1(check_str.encode()).hexdigest()
|
| 26 |
+
|
| 27 |
+
if digest == msg_signature:
|
| 28 |
+
return PlainTextResponse(echostr)
|
| 29 |
else:
|
| 30 |
return PlainTextResponse("invalid")
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return PlainTextResponse(f"error: {str(e)}")
|
| 33 |
|
| 34 |
+
# 接收消息
|
| 35 |
@app.post("/gateway/wecom")
|
| 36 |
+
async def message():
|
| 37 |
+
return PlainTextResponse("ok")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
# 主页
|
| 40 |
+
@app.get("/")
|
| 41 |
+
async def root():
|
| 42 |
+
return {"status": "running", "wecom": "/gateway/wecom"}
|