This commit is contained in:
jeremygan2021
2026-02-10 22:38:39 +08:00
parent 0ea5975c68
commit c55c4ca374
3 changed files with 26 additions and 4 deletions

View File

@@ -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',
},
}

View File

@@ -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('/'):

View File

@@ -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: