|
@@ -52,38 +52,58 @@ class OpenTransferService:
|
|
|
cls,
|
|
cls,
|
|
|
auth: AuthSchema,
|
|
auth: AuthSchema,
|
|
|
order_no: str,
|
|
order_no: str,
|
|
|
- ):
|
|
|
|
|
|
|
+ ) -> bool:
|
|
|
|
|
+ """
|
|
|
|
|
+ 发送转账回调通知
|
|
|
|
|
+
|
|
|
|
|
+ 参数:
|
|
|
|
|
+ - auth: 认证信息
|
|
|
|
|
+ - order_no: 订单号
|
|
|
|
|
+
|
|
|
|
|
+ 返回:
|
|
|
|
|
+ - bool: 是否成功发送通知
|
|
|
|
|
+ """
|
|
|
try:
|
|
try:
|
|
|
- crud = TransferCRUD(auth)
|
|
|
|
|
- transfer = await crud.get_by_order_no(order_no)
|
|
|
|
|
|
|
+ transfer_crud = TransferCRUD(auth)
|
|
|
|
|
+ transfer = await transfer_crud.get_by_order_no(order_no)
|
|
|
|
|
|
|
|
if not transfer or not transfer.out_biz_no:
|
|
if not transfer or not transfer.out_biz_no:
|
|
|
- return
|
|
|
|
|
|
|
+ log.info("回调通知: 订单不存在或缺少 out_biz_no, order_no={}", order_no)
|
|
|
|
|
+ return False
|
|
|
|
|
|
|
|
- crud = OpenTransferCRUD(auth)
|
|
|
|
|
- open_data = await crud.get(out_biz_no=transfer.out_biz_no)
|
|
|
|
|
|
|
+ open_transfer_crud = OpenTransferCRUD(auth)
|
|
|
|
|
+ open_data = await open_transfer_crud.get(out_biz_no=transfer.out_biz_no)
|
|
|
|
|
|
|
|
if not open_data:
|
|
if not open_data:
|
|
|
- return
|
|
|
|
|
|
|
+ log.info("回调通知: 开放转账记录不存在, out_biz_no={}", transfer.out_biz_no)
|
|
|
|
|
+ return False
|
|
|
|
|
|
|
|
conf = await OpenConfService.get_conf_service(auth)
|
|
conf = await OpenConfService.get_conf_service(auth)
|
|
|
if not conf:
|
|
if not conf:
|
|
|
- return
|
|
|
|
|
|
|
+ log.info("回调通知: 开放转账配置不存在, tenant_id={}", auth.tenant_id)
|
|
|
|
|
+ return False
|
|
|
|
|
+
|
|
|
|
|
+ if not conf.return_url:
|
|
|
|
|
+ log.info("回调通知: 未配置回调地址, tenant_id={}", auth.tenant_id)
|
|
|
|
|
+ return False
|
|
|
|
|
|
|
|
result = TransferOutSchema.model_validate(transfer).model_dump(exclude_none=True)
|
|
result = TransferOutSchema.model_validate(transfer).model_dump(exclude_none=True)
|
|
|
result["third_biz_no"] = open_data.third_biz_no
|
|
result["third_biz_no"] = open_data.third_biz_no
|
|
|
|
|
+
|
|
|
notify_id = f"n{get_snowflake_id()}"
|
|
notify_id = f"n{get_snowflake_id()}"
|
|
|
timestamp = int(time.time() * 1000)
|
|
timestamp = int(time.time() * 1000)
|
|
|
content = json.dumps(result)
|
|
content = json.dumps(result)
|
|
|
|
|
|
|
|
- async with aiohttp.ClientSession() as session:
|
|
|
|
|
- log.info(f"调用回调接口: {conf.return_url}")
|
|
|
|
|
|
|
+ timeout = aiohttp.ClientTimeout(total=30)
|
|
|
|
|
+ async with aiohttp.ClientSession(timeout=timeout) as session:
|
|
|
|
|
+ log.info("回调通知: order_no={}, url={}, notify_id={}", order_no, conf.return_url, notify_id)
|
|
|
await fetch_manual_retry(
|
|
await fetch_manual_retry(
|
|
|
session, conf.return_url, notify_id, conf.app_id, timestamp, content
|
|
session, conf.return_url, notify_id, conf.app_id, timestamp, content
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- except: #ignore
|
|
|
|
|
- pass
|
|
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ log.error("回调通知异常: order_no={}, error={}", order_no, e, exc_info=True)
|
|
|
|
|
+ return False
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|