This commit is contained in:
yumoqing 2025-12-18 14:16:35 +08:00
parent 64a2a89929
commit 3c94e3c7a4
3 changed files with 11 additions and 16 deletions

View File

@ -124,18 +124,13 @@ async def refund_payment(request, params_kw=None):
raise e raise e
# 回调入口:你可把厂商回调用各自 endpoint 再转发到这里,或在厂商控制台按各自 URL 配置 # 回调入口:你可把厂商回调用各自 endpoint 再转发到这里,或在厂商控制台按各自 URL 配置
async def payment_notify(request, params_kw=None): async def payment_notify(request, provider, params_kw):
if params_kw is None:
params_kw = request.params_kw
provider = params_kw.provider
if PROVIDERS[provider] is None: if PROVIDERS[provider] is None:
e = Exception(f'{provider} cannot pay') e = Exception(f'{provider} cannot pay')
exception(f'{e}') exception(f'{e}')
return return
try: try:
headers = dict(request.headers) data = await PROVIDERS[provider].handle_notify(request, params_kw)
body = await request.text()
data = await PROVIDERS[provider].handle_notify(headers, body)
except Exception as e: except Exception as e:
e = Exception(f'{provider} cannot pay') e = Exception(f'{provider} cannot pay')
exception(f'{e}') exception(f'{e}')

View File

@ -60,6 +60,7 @@ class PaymentLog:
async with self.db.sqlorContext(dbname) as sor: async with self.db.sqlorContext(dbname) as sor:
ns = { ns = {
"id": logid, "id": logid,
"payment_status":'1',
"payed_timestamp": timestampstr() "payed_timestamp": timestampstr()
} }
await sor.U('payment_log', ns) await sor.U('payment_log', ns)
@ -76,18 +77,18 @@ async def unipay_accounting(request, data):
db = DBPools() db = DBPools()
dbname = env.get_module_dbname('unipay') dbname = env.get_module_dbname('unipay')
async with db.sqlorContext(dbname) as sor: async with db.sqlorContext(dbname) as sor:
recs = await sor.R('payment_log', {'id', logid}) recs = await sor.R('payment_log', {'id': logid})
if len(recs) < 1: if len(recs) < 1:
e = Exception(f'{logid} not found {data=}') e = Exception(f'{logid} not found {data=}')
exception(f'{e}') exception(f'{e}')
raise e raise e
r = recs[0] r = recs[0]
if r.status == '2': if r.payment_status == '2':
e = Exception(f'{logid} payment_log status({r.status}) is already accounted') e = Exception(f'{logid} payment_log status({r.payment_status}) is already accounted')
exception(f'{e}') exception(f'{e}')
return True return True
if r.status != '1': if r.payment_status != '1':
e = Exception(f'{logid} payment_log status({r.status}) not correct') e = Exception(f'{logid} payment_log status({r.payment_status}) not correct')
exception(f'{e}') exception(f'{e}')
return False return False
await env.recharge_accounting(sor, await env.recharge_accounting(sor,
@ -99,7 +100,7 @@ async def unipay_accounting(request, data):
r.pay_feerate r.pay_feerate
) )
await sor.U('payment_log', {'id': logid, await sor.U('payment_log', {'id': logid,
'status': '2', 'payment_status': '2',
'channel_trade_id': trade_id 'channel_trade_id': trade_id
}) })

View File

@ -192,13 +192,12 @@ class AlipayGateway(Gateway):
# 回调 / 异步通知(验签) # 回调 / 异步通知(验签)
# ============================================================================== # ==============================================================================
async def handle_notify(self, request) -> Dict[str, Any]: async def handle_notify(self, request, params) -> Dict[str, Any]:
""" """
支付宝异步通知验签 支付宝异步通知验签
"""
self.setup_session()
form = await request.post() form = await request.post()
params = dict(form) params = dict(form)
"""
sign = params.pop("sign", None) sign = params.pop("sign", None)
sign_type = params.pop("sign_type", None) sign_type = params.pop("sign_type", None)