支付宝微信交易流水号保存

parent f56e0d8c
...@@ -125,7 +125,7 @@ class TopUpOrderNotify(Resource): ...@@ -125,7 +125,7 @@ class TopUpOrderNotify(Resource):
res_info = request.stream.read(request.content_length or 0).decode() res_info = request.stream.read(request.content_length or 0).decode()
res = order_service.alipayWxPayCheck(res_info) res = order_service.alipayWxPayCheck(res_info)
if res['success']: if res['success']:
order_service.topUpSuccessAction(res['order_no']) order_service.topUpSuccessAction(res['order_no'], res['transaction_id'])
resp = make_response(res['body']) resp = make_response(res['body'])
resp.hearders = res['header'] resp.hearders = res['header']
return resp return resp
...@@ -156,7 +156,7 @@ class ConsumeOrderNotify(Resource): ...@@ -156,7 +156,7 @@ class ConsumeOrderNotify(Resource):
res_info = request.stream.read(request.content_length or 0).decode() res_info = request.stream.read(request.content_length or 0).decode()
res = order_service.alipayWxPayCheck(res_info) res = order_service.alipayWxPayCheck(res_info)
if res['success']: if res['success']:
order_service.consumeSucessAction(res['order_no']) order_service.consumeSucessAction(res['order_no'], res['transaction_id'])
resp = make_response(res['body']) resp = make_response(res['body'])
resp.hearders = res['header'] resp.hearders = res['header']
return resp return resp
......
...@@ -233,7 +233,7 @@ class CurriculumOrderService: ...@@ -233,7 +233,7 @@ class CurriculumOrderService:
return pay_params return pay_params
def topUpSuccessAction(order_no): def topUpSuccessAction(order_no, transaction_id):
""".""" """."""
with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_pay_engine) as tamp_pay: with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_pay_engine) as tamp_pay:
tamp_user_session, tamp_pay_session = tamp_user.session, tamp_pay.session tamp_user_session, tamp_pay_session = tamp_user.session, tamp_pay.session
...@@ -247,6 +247,7 @@ def topUpSuccessAction(order_no): ...@@ -247,6 +247,7 @@ def topUpSuccessAction(order_no):
return False return False
tamp_user_session.query(OrderFlow).filter(OrderFlow.ab_ordernum == order_no).update({ tamp_user_session.query(OrderFlow).filter(OrderFlow.ab_ordernum == order_no).update({
'ab_status': 'SUCCESS', 'ab_status': 'SUCCESS',
'transaction_serial_no': transaction_id,
'pay_time': datetime.datetime.now(), 'pay_time': datetime.datetime.now(),
'complete_time': datetime.datetime.now() 'complete_time': datetime.datetime.now()
}) })
...@@ -264,7 +265,7 @@ def topUpSuccessAction(order_no): ...@@ -264,7 +265,7 @@ def topUpSuccessAction(order_no):
def consumeSucessAction(order_no): def consumeSucessAction(order_no, transaction_id):
""".""" """."""
with TAMP_SQL(tamp_user_engine) as tamp_user: with TAMP_SQL(tamp_user_engine) as tamp_user:
tamp_user_session = tamp_user.session tamp_user_session = tamp_user.session
...@@ -278,6 +279,7 @@ def consumeSucessAction(order_no): ...@@ -278,6 +279,7 @@ def consumeSucessAction(order_no):
return False return False
tamp_user_session.query(OrderFlow).filter(OrderFlow.ab_ordernum == order_no).update({ tamp_user_session.query(OrderFlow).filter(OrderFlow.ab_ordernum == order_no).update({
'ab_status': 'SUCCESS', 'ab_status': 'SUCCESS',
'transaction_serial_no': transaction_id,
'pay_time': datetime.datetime.now(), 'pay_time': datetime.datetime.now(),
'complete_time': datetime.datetime.now() 'complete_time': datetime.datetime.now()
}) })
...@@ -314,27 +316,30 @@ def dict2xml(dict_): ...@@ -314,27 +316,30 @@ def dict2xml(dict_):
def alipayWxPayCheck(res_info): def alipayWxPayCheck(res_info):
"""支付宝,微信支付异步通知""" """支付宝,微信支付异步通知"""
success = False success = False
body = None body = ''
transaction_id = ''
header = {'Content-Type': 'application/text'} header = {'Content-Type': 'application/text'}
res = {} res = {}
if 'trade_status' in res_info: if 'xml' in res_info:
# 微信支付
res = xml2dict(res_info)
if res['return_code'] == 'SUCCESS' and res['result_code'] == 'SUCCESS':
success = True
transaction_id = res.get('transaction_id', '')
header = {'Content-Type': 'application/xml'}
body = '<xml> <return_code><![CDATA[SUCCESS]]></return_code> <return_msg><![CDATA[OK]]></return_msg> </xml>'
else:
# 支付宝支付 # 支付宝支付
res_info = res_info.split('&') res_info = res_info.split('&')
for ss in res_info: for ss in res_info:
key, value = ss.split('=') key, value = ss.split('=')
res[key] = value res[key] = value
if res['trade_status'] == 'TRADE_SUCCESS': if res['code'] == '10000':
success = True success = True
transaction_id = res.get('trade_no', '')
body = 'success'.encode() body = 'success'.encode()
else:
# 微信支付
res = xml2dict(res_info)
if res['result_code'] == 'SUCCESS' and res['return_code'] == 'SUCCESS':
success = True
header = {'Content-Type': 'application/xml'}
body = '<xml> <return_code><![CDATA[SUCCESS]]></return_code> <return_msg><![CDATA[OK]]></return_msg> </xml>'
return {'success': success, 'header': header, 'body': body, 'order_no': res['out_trade_no']} return {'success': success, 'header': header, 'body': body, 'order_no': res['out_trade_no'], 'transaction_id': transaction_id}
def getAllOrders(args): def getAllOrders(args):
......
...@@ -33292,3 +33292,47 @@ WHERE order_flow.createby = %(createby_1)s AND order_flow.ab_proid = %(ab_proid_ ...@@ -33292,3 +33292,47 @@ WHERE order_flow.createby = %(createby_1)s AND order_flow.ab_proid = %(ab_proid_
2020-11-29 09:03:27 Sun sqlalchemy.engine.base.Engine INFO {'id': 'order_flow160661180784118', 'ab_ordernum': '20201129160661180782916', 'ab_price': None, 'ab_score': None, 'ab_score_deduct': None, 'ab_account_deduct': None, 'ab_payment': 100, 'ab_pay_mode': 6, 'ab_total_money': None, 'ab_type': 5, 'ab_proid': 'CURRICULUM_RES15916044963930', 'ab_pro_siid': None, 'ab_si_type': None, 'ab_si_name': None, 'ab_si_code': None, 'ab_si_pattern': None, 'ab_status': 'WAIT', 'ab_rights_status': None, 'createby': '193779307976941568', 'updatetime': None, 'updateby': None, 'deletetag': '0', 'unionid': None, 'transaction_serial_no': None} 2020-11-29 09:03:27 Sun sqlalchemy.engine.base.Engine INFO {'id': 'order_flow160661180784118', 'ab_ordernum': '20201129160661180782916', 'ab_price': None, 'ab_score': None, 'ab_score_deduct': None, 'ab_account_deduct': None, 'ab_payment': 100, 'ab_pay_mode': 6, 'ab_total_money': None, 'ab_type': 5, 'ab_proid': 'CURRICULUM_RES15916044963930', 'ab_pro_siid': None, 'ab_si_type': None, 'ab_si_name': None, 'ab_si_code': None, 'ab_si_pattern': None, 'ab_status': 'WAIT', 'ab_rights_status': None, 'createby': '193779307976941568', 'updatetime': None, 'updateby': None, 'deletetag': '0', 'unionid': None, 'transaction_serial_no': None}
2020-11-29 09:03:27 Sun sqlalchemy.engine.base.Engine INFO COMMIT 2020-11-29 09:03:27 Sun sqlalchemy.engine.base.Engine INFO COMMIT
2020-11-29 09:03:28 Sun werkzeug INFO 127.0.0.1 - - [29/Nov/2020 09:03:28] "POST /tamp_order/micro_shop/consumeOrder HTTP/1.1" 200 - 2020-11-29 09:03:28 Sun werkzeug INFO 127.0.0.1 - - [29/Nov/2020 09:03:28] "POST /tamp_order/micro_shop/consumeOrder HTTP/1.1" 200 -
2020-11-29 09:27:23 Sun werkzeug INFO * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
2020-11-29 09:27:23 Sun werkzeug INFO * Restarting with stat
2020-11-29 09:27:25 Sun werkzeug WARNING * Debugger is active!
2020-11-29 09:27:25 Sun werkzeug INFO * Debugger PIN: 191-123-093
2020-11-29 09:37:01 Sun werkzeug INFO * Detected change in '/Users/pengxiong/Desktop/tamp_course_order/app/service/order_service.py', reloading
2020-11-29 09:37:02 Sun werkzeug INFO * Restarting with stat
2020-11-29 09:37:03 Sun werkzeug WARNING * Debugger is active!
2020-11-29 09:37:03 Sun werkzeug INFO * Debugger PIN: 191-123-093
2020-11-29 09:41:16 Sun werkzeug INFO * Detected change in '/Users/pengxiong/Desktop/tamp_course_order/app/service/order_service.py', reloading
2020-11-29 09:41:17 Sun werkzeug INFO * Restarting with stat
2020-11-29 09:41:18 Sun werkzeug WARNING * Debugger is active!
2020-11-29 09:41:18 Sun werkzeug INFO * Debugger PIN: 191-123-093
2020-11-29 09:41:40 Sun werkzeug INFO * Detected change in '/Users/pengxiong/Desktop/tamp_course_order/app/service/order_service.py', reloading
2020-11-29 09:41:40 Sun werkzeug INFO * Restarting with stat
2020-11-29 09:41:41 Sun werkzeug WARNING * Debugger is active!
2020-11-29 09:41:41 Sun werkzeug INFO * Debugger PIN: 191-123-093
2020-11-29 09:41:50 Sun werkzeug INFO * Detected change in '/Users/pengxiong/Desktop/tamp_course_order/app/service/order_service.py', reloading
2020-11-29 09:41:50 Sun werkzeug INFO * Restarting with stat
2020-11-29 09:41:52 Sun werkzeug WARNING * Debugger is active!
2020-11-29 09:41:52 Sun werkzeug INFO * Debugger PIN: 191-123-093
2020-11-29 09:42:11 Sun werkzeug INFO * Detected change in '/Users/pengxiong/Desktop/tamp_course_order/app/service/order_service.py', reloading
2020-11-29 09:42:11 Sun werkzeug INFO * Restarting with stat
2020-11-29 09:42:13 Sun werkzeug WARNING * Debugger is active!
2020-11-29 09:42:13 Sun werkzeug INFO * Debugger PIN: 191-123-093
2020-11-29 09:42:41 Sun werkzeug INFO * Detected change in '/Users/pengxiong/Desktop/tamp_course_order/app/service/order_service.py', reloading
2020-11-29 09:42:41 Sun werkzeug INFO * Restarting with stat
2020-11-29 09:42:42 Sun werkzeug WARNING * Debugger is active!
2020-11-29 09:42:42 Sun werkzeug INFO * Debugger PIN: 191-123-093
2020-11-29 09:43:43 Sun werkzeug INFO * Detected change in '/Users/pengxiong/Desktop/tamp_course_order/app/controller/order.py', reloading
2020-11-29 09:43:43 Sun werkzeug INFO * Restarting with stat
2020-11-29 09:43:45 Sun werkzeug WARNING * Debugger is active!
2020-11-29 09:43:45 Sun werkzeug INFO * Debugger PIN: 191-123-093
2020-11-29 09:45:26 Sun werkzeug INFO * Detected change in '/Users/pengxiong/Desktop/tamp_course_order/app/controller/order.py', reloading
2020-11-29 09:45:27 Sun werkzeug INFO * Restarting with stat
2020-11-29 09:45:28 Sun werkzeug WARNING * Debugger is active!
2020-11-29 09:45:28 Sun werkzeug INFO * Debugger PIN: 191-123-093
2020-11-29 09:45:58 Sun werkzeug INFO * Detected change in '/Users/pengxiong/Desktop/tamp_course_order/app/controller/order.py', reloading
2020-11-29 09:45:58 Sun werkzeug INFO * Restarting with stat
2020-11-29 09:45:59 Sun werkzeug WARNING * Debugger is active!
2020-11-29 09:45:59 Sun werkzeug INFO * Debugger PIN: 191-123-093
2020-11-29 09:46:10 Sun werkzeug INFO * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
2020-11-29 09:46:10 Sun werkzeug INFO * Restarting with stat
2020-11-29 09:46:12 Sun werkzeug WARNING * Debugger is active!
2020-11-29 09:46:12 Sun werkzeug INFO * Debugger PIN: 191-123-093
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment