添加测试日志
This commit is contained in:
parent
2b01e0adec
commit
b552ac56b0
Binary file not shown.
@ -7,12 +7,16 @@ mode do not require credentials or network access.
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .config import settings
|
from .config import settings
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AlipayTransferError(RuntimeError):
|
class AlipayTransferError(RuntimeError):
|
||||||
def __init__(self, message: str, code: str = "", ambiguous: bool = False):
|
def __init__(self, message: str, code: str = "", ambiguous: bool = False):
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
@ -49,6 +53,11 @@ def validate_configuration() -> None:
|
|||||||
raise AlipayTransferError("应用公钥证书与应用私钥不匹配")
|
raise AlipayTransferError("应用公钥证书与应用私钥不匹配")
|
||||||
else:
|
else:
|
||||||
_sdk_key(_read_key(settings.alipay_public_key_path, "支付宝公钥"), private=False)
|
_sdk_key(_read_key(settings.alipay_public_key_path, "支付宝公钥"), private=False)
|
||||||
|
logger.info(
|
||||||
|
"Alipay provider configuration validated: scene=%s certificate_mode=%s transfer_scene_report_schema=佣金报酬说明",
|
||||||
|
settings.alipay_transfer_scene_name,
|
||||||
|
_certificate_mode_enabled(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _certificate_mode_enabled() -> bool:
|
def _certificate_mode_enabled() -> bool:
|
||||||
@ -278,6 +287,18 @@ def transfer(*, out_biz_no: str, amount_fen: int, account: str, payee_name: str,
|
|||||||
payee.identity_type = "ALIPAY_LOGON_ID"
|
payee.identity_type = "ALIPAY_LOGON_ID"
|
||||||
payee.name = payee_name
|
payee.name = payee_name
|
||||||
model.payee_info = payee
|
model.payee_info = payee
|
||||||
|
# Keep a deploy-time diagnostic in the server log without exposing the
|
||||||
|
# recipient account, name, private key, or certificate data. This makes
|
||||||
|
# it possible to distinguish an old server build from an Alipay rejection.
|
||||||
|
logger.info(
|
||||||
|
"Alipay transfer request prepared: scene=%s info_type=%s info_content=%s amount=%s biz_scene=%s product_code=%s",
|
||||||
|
model.transfer_scene_name,
|
||||||
|
reward_description.info_type,
|
||||||
|
reward_description.info_content,
|
||||||
|
model.trans_amount,
|
||||||
|
model.biz_scene,
|
||||||
|
model.product_code,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
request = AlipayFundTransUniTransferRequest(biz_model=model)
|
request = AlipayFundTransUniTransferRequest(biz_model=model)
|
||||||
if settings.alipay_notify_url:
|
if settings.alipay_notify_url:
|
||||||
@ -290,7 +311,13 @@ def transfer(*, out_biz_no: str, amount_fen: int, account: str, payee_name: str,
|
|||||||
raise
|
raise
|
||||||
provider_error = _provider_error_from_exception(exc)
|
provider_error = _provider_error_from_exception(exc)
|
||||||
if provider_error:
|
if provider_error:
|
||||||
|
logger.error(
|
||||||
|
"Alipay transfer rejected: code=%s message=%s",
|
||||||
|
provider_error.code,
|
||||||
|
provider_error,
|
||||||
|
)
|
||||||
raise provider_error from exc
|
raise provider_error from exc
|
||||||
|
logger.exception("Alipay transfer request failed without a structured provider response")
|
||||||
raise AlipayTransferError(f"支付宝转账请求失败:{exc}", ambiguous=True) from exc
|
raise AlipayTransferError(f"支付宝转账请求失败:{exc}", ambiguous=True) from exc
|
||||||
return {
|
return {
|
||||||
"out_biz_no": response.out_biz_no or out_biz_no,
|
"out_biz_no": response.out_biz_no or out_biz_no,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user