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

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