diff --git a/app/api/endpoints/message.py b/app/api/endpoints/message.py index 59fdd7b1..90de59d9 100644 --- a/app/api/endpoints/message.py +++ b/app/api/endpoints/message.py @@ -36,13 +36,11 @@ async def user_message(background_tasks: BackgroundTasks, request: Request): return schemas.Response(success=True) -@router.get("/", summary="微信验证") def wechat_verify(echostr: str, msg_signature: str, timestamp: Union[str, int], nonce: str) -> Any: """ 微信验证响应 """ - logger.info(f"收到微信验证请求: {echostr}") try: wxcpt = WXBizMsgCrypt(sToken=settings.WECHAT_TOKEN, sEncodingAESKey=settings.WECHAT_ENCODING_AESKEY, @@ -60,12 +58,26 @@ def wechat_verify(echostr: str, msg_signature: str, return PlainTextResponse(sEchoStr) -@router.get("/", summary="VoceChat验证") -def vocechat_verify() -> Any: +def vocechat_verify(token: str) -> Any: """ VoceChat验证响应 """ - return {"status": "OK"} + if token == settings.API_TOKEN: + return {"status": "OK"} + return {"status": "ERROR"} + + +@router.get("/", summary="回调请求验证") +def incoming_verify(token: str = None, echostr: str = None, msg_signature: str = None, + timestamp: Union[str, int] = None, nonce: str = None) -> Any: + """ + 微信/VoceChat等验证响应 + """ + logger.info(f"收到验证请求: token={token}, echostr={echostr}, " + f"msg_signature={msg_signature}, timestamp={timestamp}, nonce={nonce}") + if echostr and msg_signature and timestamp and nonce: + return wechat_verify(echostr, msg_signature, timestamp, nonce) + return vocechat_verify(token) @router.get("/switchs", summary="查询通知消息渠道开关", response_model=List[NotificationSwitch])