|
@@ -13,14 +13,15 @@ from app.plugin.module_payment.account import AccountService, TransferCRUD, Tran
|
|
|
import aiohttp
|
|
import aiohttp
|
|
|
import asyncio
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
+from ..apikey.service import TenantApiKeyService
|
|
|
|
|
|
|
|
-async def fetch_manual_retry(session, url, notify_id, app_id, timestamp, content, max_retries=2):
|
|
|
|
|
|
|
+
|
|
|
|
|
+async def fetch_manual_retry(session, url, notify_id, timestamp, content, max_retries=2):
|
|
|
for attempt in range(max_retries):
|
|
for attempt in range(max_retries):
|
|
|
try:
|
|
try:
|
|
|
log.debug("第 {} 次尝试: {}", attempt + 1, url)
|
|
log.debug("第 {} 次尝试: {}", attempt + 1, url)
|
|
|
form_data = aiohttp.FormData()
|
|
form_data = aiohttp.FormData()
|
|
|
form_data.add_field('notify_id', notify_id)
|
|
form_data.add_field('notify_id', notify_id)
|
|
|
- form_data.add_field('app_id', app_id)
|
|
|
|
|
form_data.add_field('timestamp', timestamp)
|
|
form_data.add_field('timestamp', timestamp)
|
|
|
form_data.add_field('content', content)
|
|
form_data.add_field('content', content)
|
|
|
async with session.post(url=url, data=form_data) as response:
|
|
async with session.post(url=url, data=form_data) as response:
|
|
@@ -80,15 +81,23 @@ class OpenTransferService:
|
|
|
|
|
|
|
|
auth.tenant_id = open_data.tenant_id
|
|
auth.tenant_id = open_data.tenant_id
|
|
|
auth.check_data_scope = True
|
|
auth.check_data_scope = True
|
|
|
- conf = await OpenConfService.get_conf_service(auth)
|
|
|
|
|
- if not conf:
|
|
|
|
|
- log.info("回调通知: 开放转账配置不存在, tenant_id={}", auth.tenant_id)
|
|
|
|
|
- return False
|
|
|
|
|
-
|
|
|
|
|
- log.info("回调通知: 开放转账配置 app_id={}, return_url={}, tenant_id={}", conf.app_id, conf.return_url, auth.tenant_id)
|
|
|
|
|
|
|
|
|
|
- if not conf.return_url:
|
|
|
|
|
- log.info("回调通知: 未配置回调地址, tenant_id={}", auth.tenant_id)
|
|
|
|
|
|
|
+ apikey_data = None
|
|
|
|
|
+
|
|
|
|
|
+ # 先从apikey那return_url,否则使用conf
|
|
|
|
|
+ if open_data.api_key:
|
|
|
|
|
+ apikey_data = await TenantApiKeyService.get_apikey_service(auth=auth, api_key=open_data.api_key)
|
|
|
|
|
+ if apikey_data:
|
|
|
|
|
+ return_url = apikey_data.return_url
|
|
|
|
|
+ else:
|
|
|
|
|
+ conf = await OpenConfService.get_conf_service(auth)
|
|
|
|
|
+ if not conf:
|
|
|
|
|
+ log.info("回调通知: 开放转账配置不存在, tenant_id={}", auth.tenant_id)
|
|
|
|
|
+ return False
|
|
|
|
|
+ return_url = conf.return_url
|
|
|
|
|
+
|
|
|
|
|
+ if not return_url:
|
|
|
|
|
+ log.info("回调通知: 回调地址不存在")
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
result = TransferOutSchema.model_validate(transfer)
|
|
result = TransferOutSchema.model_validate(transfer)
|
|
@@ -100,10 +109,11 @@ class OpenTransferService:
|
|
|
|
|
|
|
|
timeout = aiohttp.ClientTimeout(total=30)
|
|
timeout = aiohttp.ClientTimeout(total=30)
|
|
|
async with aiohttp.ClientSession(timeout=timeout) as session:
|
|
async with aiohttp.ClientSession(timeout=timeout) as session:
|
|
|
- log.info("回调通知: order_no={}, url={}, notify_id={}", order_no, conf.return_url, notify_id)
|
|
|
|
|
|
|
+ log.info("回调通知: order_no={}, url={}, notify_id={}", order_no, return_url, notify_id)
|
|
|
await fetch_manual_retry(
|
|
await fetch_manual_retry(
|
|
|
- session, conf.return_url, notify_id, conf.app_id, timestamp, content
|
|
|
|
|
|
|
+ session, return_url, notify_id, timestamp, content
|
|
|
)
|
|
)
|
|
|
|
|
+ return True
|
|
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
log.error("回调通知异常: order_no={}, error={}", order_no, e, exc_info=True)
|
|
log.error("回调通知异常: order_no={}, error={}", order_no, e, exc_info=True)
|
|
@@ -151,6 +161,7 @@ class OpenTransferService:
|
|
|
create_data = {
|
|
create_data = {
|
|
|
"third_biz_no": third_biz_no,
|
|
"third_biz_no": third_biz_no,
|
|
|
"out_biz_no": result.out_biz_no,
|
|
"out_biz_no": result.out_biz_no,
|
|
|
|
|
+ "api_key": data.api_key,
|
|
|
}
|
|
}
|
|
|
await crud.create(create_data)
|
|
await crud.create(create_data)
|
|
|
|
|
|