48 lines
2.2 KiB
Plaintext
48 lines
2.2 KiB
Plaintext
async def get_weixpay(ns):
|
|
"""
|
|
微信支付回调
|
|
"""
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
if ns['summary'] != "支付成功":
|
|
return {'status': False, 'msg': '未支付'}
|
|
nonce = ns['resource']['nonce']
|
|
ciphertext = ns['resource']['ciphertext']
|
|
associated_data = ns['resource']['associated_data']
|
|
apiv3_key = 'f1a37b0926b37a6af65f077e2684af45'
|
|
key_bytes = apiv3_key.encode('UTF-8')
|
|
nonce_bytes = nonce.encode('UTF-8')
|
|
associated_data_bytes = associated_data.encode('UTF-8')
|
|
data = base64.b64decode(ciphertext)
|
|
aesgcm = AESGCM(key=key_bytes)
|
|
result = aesgcm.decrypt(nonce=nonce_bytes, data=data, associated_data=associated_data_bytes).decode(
|
|
'UTF-8')
|
|
result = eval(result)
|
|
date = await get_business_date(sor=None)
|
|
try:
|
|
recharge_logdict = {}
|
|
recharge_logdict['id'] = result['out_trade_no']
|
|
recharge_logdict['recharge_timestamp'] = datetime.datetime.now()
|
|
recharge_logdict['recharge_date'] = date
|
|
recharge_logdict['weixin_sno'] = result['transaction_id']
|
|
recharge_logdict['recharge_amt'] = result['amount']['total'] / 100
|
|
await sor.U('recharge_log', recharge_logdict)
|
|
recharge_logdata = await sor.R('recharge_log', {'id': result['out_trade_no']})
|
|
|
|
recharge_amt = recharge_logdata[0]['recharge_amt']
|
|
fee_amts = float(recharge_amt) * 0.006
|
|
fee_amte = float(format(fee_amts, '.2f'))
|
|
recharge_log = {'customerid': recharge_logdata[0]['customerid'],
|
|
'recharge_amt': float(result['amount']['total'] / 100),
|
|
'action': 'RECHARGE_ALIPAY', 'recharge_path': '0', 'recharge_date': date,
|
|
'fee_amt': fee_amte}
|
|
ra = AlipayRechargeAccounting(recharge_log)
|
|
await ra.accounting(sor)
|
|
return {'status': True, 'msg': '回调成功'}
|
|
except Exception as error:
|
|
raise error
|
|
return {'status': False, 'msg': '回调失败'}
|
|
|
|
|
|
ret = await get_weixpay(params_kw)
|
|
return ret |