diff --git a/backend/config/settings.py b/backend/config/settings.py index e37c7c1..9033074 100644 --- a/backend/config/settings.py +++ b/backend/config/settings.py @@ -194,3 +194,17 @@ UNFOLD = { # 禁用自动补齐斜杠,防止破坏微信支付的 POST 回调 APPEND_SLASH = False + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler', + }, + }, + 'root': { + 'handlers': ['console'], + 'level': 'INFO', + }, +} diff --git a/backend/shop/views.py b/backend/shop/views.py index 56c0576..1fd53e8 100644 --- a/backend/shop/views.py +++ b/backend/shop/views.py @@ -71,11 +71,19 @@ def get_wechat_pay_client(): if private_key: # 统一处理私钥格式 private_key = private_key.strip() - if 'BEGIN PRIVATE KEY' not in private_key: + + # 移除可能存在的首尾空白字符 + if 'BEGIN PRIVATE KEY' in private_key: + # 如果已经包含 PEM 头,尝试清理并重新格式化 + lines = private_key.split('\n') + clean_lines = [line.strip() for line in lines if line.strip()] + private_key = '\n'.join(clean_lines) + else: + # 如果没有头尾,说明是纯 base64 内容,尝试添加 private_key = f"-----BEGIN PRIVATE KEY-----\n{private_key}\n-----END PRIVATE KEY-----" if not private_key: - return None, "缺少商户私钥" + return None, "缺少商户私钥 (未找到文件且数据库配置为空)" # 确保回调地址以斜杠结尾 if not notify_url.endswith('/'): diff --git a/docker-compose.yml b/docker-compose.yml index 9b66fde..b77462f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,8 @@ services: backend: build: ./backend - # 使用 gunicorn 替代 runserver,提高稳定性 - command: sh -c "python manage.py migrate && gunicorn --bind 0.0.0.0:8000 config.wsgi:application" + # 使用 gunicorn 替代 runserver,提高稳定性,并捕获标准输出 + command: sh -c "python manage.py collectstatic --noinput && python manage.py migrate && gunicorn --bind 0.0.0.0:8000 --access-logfile - --error-logfile - config.wsgi:application" volumes: - ./backend:/app ports: