打印日志

parent a1cfb1aa
......@@ -13,6 +13,7 @@ from flask import jsonify, make_response, request
from app.api.engine import config, env
from app.config.errors import Errors
from app.api.engine import logging
class CustomFlaskErr(Exception):
......@@ -64,22 +65,21 @@ def add_errorhandler(app):
def before_request():
# token鉴权
token = request.headers.get('tampToken', '')
# token = 'eyJhbHQiOiJIUzI1NiIsImFsZyI6IkhTMjU2IiwidHlwIjoiSldUIn0.eyJwYXlsb2FkIjoidGFtcC8xOTM3NzkzMDc5NzY5NDE1NjgiLCJpc3MiOiJjYWl4aWFvcXVhbiIsImlhdCI6MTYwNjI5MDYzMH0.WnADEiWd27A8wr2DmOyX1kcs0dWLxpoO-k1yiF0qbBk'
url = config[env]['token_auth_url']
print(request.path)
start = time.time()
if request.path in ['/tamp_order/micro_shop/topUpOrderNotify', '/tamp_order/micro_shop/consumeOrderNotify']:
pass
else:
requests.adapters.DEFAULT_RETRIES = 5 # 增加重连次数
s = requests.session()
s.keep_alive = False
res = s.get(url+'?tampToken='+token)
print('token鉴权时间', time.time() - start)
resp = res.json()
if resp['statusCode'] != "0000":
raise CustomFlaskErr(Errors.TOKEN_INVALID)
request.user_id = resp['attributes']
try:
requests.adapters.DEFAULT_RETRIES = 5 # 增加重连次数
s = requests.session()
s.keep_alive = False
res = s.get(url+'?tampToken='+token)
resp = res.json()
if resp['statusCode'] != "0000":
raise CustomFlaskErr(Errors.TOKEN_INVALID)
request.user_id = resp['attributes']
except:
logging.error('token鉴权失败', token)
request.return_success = {'statusCode': "0000", 'message': 'ok'}
@app.after_request
......
......@@ -127,7 +127,7 @@ class TopUpOrderNotify(Resource):
def post(self):
"""."""
res_info = request.stream.read(request.content_length or 0).decode()
print(res_info)
logging.info('支付成功通知信息', res_info)
res = order_service.alipayWxPayCheck(res_info)
if res['success']:
order_service.topUpSuccessAction(res['order_no'], res['transaction_id'])
......@@ -159,7 +159,7 @@ class ConsumeOrderNotify(Resource):
def post(self):
"""."""
res_info = request.stream.read(request.content_length or 0).decode()
print(res_info)
logging.info('支付成功通知信息', res_info)
res = order_service.alipayWxPayCheck(res_info)
if res['success']:
order_service.consumeSucessAction(res['order_no'], res['transaction_id'])
......
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