Commit 522c6b92 by Aeolus

update

parent 742b540a
#!/usr/bin/.env python
import json
import logging
import os
from threading import Lock
import requests
from flask import Flask, render_template, session, request
from flask_socketio import SocketIO, Namespace, emit, join_room, leave_room, \
close_room, rooms, disconnect
......@@ -170,12 +173,28 @@ class MyNamespace(Namespace):
def on_write_sn(self, message):
try:
sn = message["sn"]
token = message["Authorization"]
last_four = hex(int(sn[-4:])).replace('0x', '').zfill(4)
sn = sn[:-4] + last_four
# TODO 校验sn是否重复
#
# TODO 校验sn是否重复
sn = sn[2:]
power_no = sn[4:]
url = "https://guide.ssw-htzn.com/business_web/power/check_write_power_no"
headers = {
"Authorization": token,
"platform": "business_web"
}
data = {"power_no": sn}
json_data = json.dumps(data, ensure_ascii=False)
result = requests.post(url=url, data=json_data.encode('utf-8'), headers=headers, verify=None)
print(result.text)
result = json.loads(result.text)
if int(result["error_code"]) != 0:
emit('write_sn',
{'data': None, 'error_code': 1005,
'error_message': 'sn数据重复,请重试, sn exist!'})
hcontext = self.scard.establish_context()
result = self.scard.find_self_reader(hcontext)
......@@ -183,7 +202,6 @@ class MyNamespace(Namespace):
emit('write_sn',
{'data': None, 'error_code': 1001, 'error_message': '读卡器连接失败, reader connect error'})
sn = sn[2:]
write_command = [0xFF, 0xD6, 0x00, 17, 0x10]
write_command += [int(i, 16) for i in sn]
result = self.scard.card_transmit(hcontext, self.scard.reader, write_command)
......@@ -213,16 +231,8 @@ class MyNamespace(Namespace):
def on_ping(self):
emit('my_pong')
def on_connect(self, auth):
if request.remote_addr == '127.0.0.1':
pass
else:
print(auth)
if auth["token"] != '1234':
disconnect()
else:
print("connect success")
emit('my_response', {'data': 'Connected', 'count': 0})
def on_connect(self):
emit('my_response', {'data': 'Connected'})
def on_disconnect(self):
print('Client disconnected', request.sid)
......
......@@ -58,68 +58,6 @@ def jwt_authentication():
"""
if current_app.name == "nfc_socket":
NO_AUTH_CHECK_URL = [url_for('account.login'), ]
elif current_app.name == "business_mp":
NO_AUTH_CHECK_URL = [url_for('account.test'), url_for('account.login'), url_for('account.send_code'),
url_for('tool.tool_reset')]
if request.path not in NO_AUTH_CHECK_URL:
token = request.headers.get('token')
if not token:
return BaseResponse(**TOKEN_NOT_VALID_ERROR)
result = AgentService.check_agent_token(token)
if result == 1:
return BaseResponse(**TOKEN_NOT_VALID_ERROR)
elif result == 2:
return BaseResponse(**TOKEN_EXPIRE_ERROR)
else:
g.user = result
logger.info("本次登录用户名称:{0},手机号:{1},类型:{2}".format(result.user_name, result.phone, result.level_desc))
return
elif current_app.name == "business_web":
NO_AUTH_CHECK_URL = [url_for('account.user_login'), url_for('account.send_code')]
if request.path not in NO_AUTH_CHECK_URL:
token = request.headers.get('Authorization')
# "校验token"
payload = verify_jwt(token)
# "判断token的校验结果"
if payload:
# "获取载荷中的信息赋值给g对象"
user_id = payload.get('user_id')
if not user_id:
return BaseResponse(**TOKEN_NOT_VALID_ERROR)
result = AgentAccount.query.filter_by(id=user_id, status=1).first()
if not result:
return BaseResponse(**TOKEN_NOT_VALID_ERROR)
g.user = result
else:
return BaseResponse(**TOKEN_NOT_VALID_ERROR)
return
elif current_app.name == "onenet":
NO_AUTH_CHECK_URL = [url_for('onenet.message_handler'), ]
elif current_app.name == "rent_core":
NO_AUTH_CHECK_URL = [url_for('wx_auth.test'),
url_for('wx_auth.mini_login'),
url_for('rent.wx_pay_callback'),
url_for('rent.test'),
url_for('rent.run_scan'),
url_for('message.message_put'),
url_for('ctrip.run_ctrip'),
url_for('coupon.openid_test'),
url_for('coupon.openid_callback'),
url_for('alltour.wx_oa_entrance'),
url_for('xiaojianwenlv.wx_oa_entrance'),
url_for('xiaojianwenlv.get_wx_media_list'),
url_for('suixinxiaojian.wx_oa_entrance'),
url_for('suixinxiaojian.get_wx_media_list'),
url_for('redpack.send_redpack'),
url_for('spot.get_spot_by_lat_lng'),
url_for('machine.get_machine_by_lat_lng'),
url_for('rent.get_machine_price'),
url_for('other.get_spot_phone'),
url_for('other.login'),
url_for('other.send_code'),
url_for('onenet.message_handler'), ]
else:
NO_AUTH_CHECK_URL = []
......
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