From 124cac88d42cbf4dcb4ebb2c1ab84d34dbf75751 Mon Sep 17 00:00:00 2001 From: xingc Date: Wed, 16 Apr 2025 19:08:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(chat=E3=80=81pay):=20=E5=A2=9E=E5=8A=A0pay?= =?UTF-8?q?=E6=B2=99=E7=9B=92=E3=80=81=E7=A7=BB=E9=99=A4=E6=9D=82=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/app.py | 26 +++++++++++--------------- core/routers/chat/handlers.py | 6 +----- core/wechat/api.py | 14 ++++---------- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/core/app.py b/core/app.py index 5605239..edd9a30 100644 --- a/core/app.py +++ b/core/app.py @@ -41,10 +41,6 @@ def create_app() -> FastAPI: for router in routers: app.include_router(router) - if settings.ENVIRONMENT != 'prod': - from fastapi.staticfiles import StaticFiles - app.mount("/uploads", StaticFiles(directory="uploads"), name="uploads") - @app.on_event('startup') async def startup_event(): redis_conn = await get_cache() @@ -80,16 +76,16 @@ def create_app() -> FastAPI: } ) - # @app.exception_handler(Exception) - # async def http_exception_handler(request: Request, exc: Exception): - # await exception_log(request, exc) - # return UJSONResponse( - # status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - # content={ - # 'status': status.HTTP_500_INTERNAL_SERVER_ERROR, - # 'data': None, - # 'message': 'Internal server error' - # } - # ) + @app.exception_handler(Exception) + async def http_exception_handler(request: Request, exc: Exception): + await exception_log(request, exc) + return UJSONResponse( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, + content={ + 'status': status.HTTP_500_INTERNAL_SERVER_ERROR, + 'data': None, + 'message': 'Internal server error' + } + ) return app diff --git a/core/routers/chat/handlers.py b/core/routers/chat/handlers.py index c07e37d..5d94ae3 100644 --- a/core/routers/chat/handlers.py +++ b/core/routers/chat/handlers.py @@ -6,11 +6,7 @@ # @Desc : import logging from datetime import datetime -from typing import List, Dict - -import redis.asyncio as aioredis from fastapi import WebSocket -from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession from core.db.crud import CRUD @@ -86,7 +82,7 @@ async def send_new_message( ) await socket_manager.broadcast_to_chat(chat_guid, send_message_schema.model_dump_json()) - await websocket.send_json(send_status_replay.model_dump_json()) + await websocket.send_text(send_status_replay.model_dump_json()) @socket_manager.handler('chat.message_read') diff --git a/core/wechat/api.py b/core/wechat/api.py index 12c0f7b..0d47951 100644 --- a/core/wechat/api.py +++ b/core/wechat/api.py @@ -144,6 +144,8 @@ class WechatPayApi(BaseClient): self.appi_key = app_key self.notify_url = notify_url self.base_url = 'https://api.mch.weixin.qq.com' + if debug: + self.base_url = f'{self.base_url}/sandboxnew' super().__init__() @staticmethod @@ -209,14 +211,6 @@ class WechatPayApi(BaseClient): wechat_pay_api = WechatPayApi( - appid=settings.APPID, mch_id=settings.PAY_MCH_ID, app_key=settings.PAY_API_KEY, notify_url=settings.PAY_NOTIFY_URL + appid=settings.APPID, mch_id=settings.PAY_MCH_ID, app_key=settings.PAY_API_KEY, + notify_url=settings.PAY_NOTIFY_URL, debug=settings.DEBUG ) - -if __name__ == '__main__': - import asyncio - - print(asyncio.run(decrypt_sensitive_data( - session_key='uuLloEnWUpnOWkpB4Oyopw==', - encrypted_data='Bzdx4BOZEJ10xf4fN2643OJaxHF/Wcj/Qv1q6M6L4MB0BBvKJRG3rlrGUYQd2nimCvDbDVPu+S3zUQidaOgyvBhDG4W0Oy8hgfeLALhqrzUo1AhTQvvxwQrntMHMRvqtdk1AzsiviaOEVGALYmuXneLD/XnGH8VzXaD2eiauzDQNCMtXVUUgB3QzIeqczr9xXSg2t6JB91m0kLs8a7FSsJAXhHIBk+58jKZjgxMUpzuJeJ/fu1Gez7q9o0iXYSVBO//KGpEVgWO0EPe4pINnwduZ3bbXF21UdRTzQ+GG2eYslXA2lespMlQWomwk5RbpVh+GWx/D29Tkprq17gkzeiiCHk9hIEHuY0+ausTbT+gOk/RG11qzYJL0nRT3uJr4GtAMKcqDV4Kmo9SThglwIg==', - iv='Nr7pQgCBMextSzroXPNsIw==' - )))