Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nfc_storage
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
冯佳佳
nfc_storage
Commits
374c2b75
Commit
374c2b75
authored
Oct 25, 2021
by
冯佳佳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
7ca9c59b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
42 deletions
+47
-42
app.py
+47
-42
No files found.
app.py
View file @
374c2b75
...
...
@@ -13,23 +13,24 @@ from flask_socketio import SocketIO, Namespace, emit, join_room, leave_room, \
from
smartcard.scard
import
*
import
smartcard.util
#
import engineio.async_drivers.gevent
import
engineio.async_drivers.gevent
import
engineio.async_drivers.threading
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
# 控制台打印的日志级别
filename
=
'nfc.log'
,
filemode
=
'a'
,
##模式,有w和a,w就是写模式,每次都会重新写日志,覆盖之前的日志
# a是追加模式,默认如果不写的话,就是追加模式
format
=
'
%(asctime)
s -
%(pathname)
s[line:
%(lineno)
d] -
%(levelname)
s:
%(message)
s'
# 日志格式
)
#
logging.basicConfig(level=logging.DEBUG, # 控制台打印的日志级别
#
filename='nfc.log',
#
filemode='a', ##模式,有w和a,w就是写模式,每次都会重新写日志,覆盖之前的日志
#
# a是追加模式,默认如果不写的话,就是追加模式
#
format=
#
'%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s'
#
# 日志格式
#
)
logger
=
logging
.
getLogger
(
__name__
)
# async_mode = 'eventlet'
# async_mode = 'gevent'
async_mode
=
'threading'
# if getattr(sys, 'frozen', False):
# template_folder = os.path.join(sys._MEIPASS, 'templates')
# static_folder = os.path.join(sys._MEIPASS, 'static')
...
...
@@ -37,9 +38,10 @@ async_mode = 'threading'
# else:
app
=
Flask
(
__name__
)
socketio
=
SocketIO
(
app
,
async_mode
=
async_mode
,
cors_allowed_origins
=
"*"
,
logger
=
True
,
engineio_logger
=
True
socketio
=
SocketIO
(
app
,
cors_allowed_origins
=
"*"
,
async_mode
=
async_mode
,
# logger=True,
# engineio_logger=True
)
...
...
@@ -331,6 +333,7 @@ class MyNamespace(Namespace):
def
on_reader_connect
(
self
,
message
):
try
:
hcontext
=
None
hcontext
=
self
.
scard
.
establish_context
()
result
=
self
.
scard
.
find_self_reader
(
hcontext
)
if
result
:
...
...
@@ -509,8 +512,9 @@ class MyNamespace(Namespace):
try
:
sn
=
message
[
"sn"
]
token
=
message
[
"Authorization"
]
last_four
=
hex
(
int
(
sn
[
-
4
:]))
.
replace
(
'0x'
,
''
)
.
zfill
(
4
)
last_four
=
hex
(
int
(
sn
[
-
4
:]))
.
replace
(
'0x'
,
''
)
.
zfill
(
4
)
.
upper
()
sn
=
sn
[:
-
4
]
+
last_four
sn
=
sn
.
upper
()
# TODO 校验sn是否重复
sn
=
sn
[
2
:]
...
...
@@ -561,21 +565,39 @@ class MyNamespace(Namespace):
def
on_delete_sn
(
self
,
message
):
try
:
sn
=
message
[
"sn"
]
password
=
message
[
"password"
]
if
password
!=
"sswnb"
:
emit
(
'delete_
all
'
,
emit
(
'delete_
sn
'
,
{
'data'
:
None
,
'error_code'
:
1008
,
'error_message'
:
'password error ,密码错误,请重试'
})
return
token
=
message
[
"Authorization"
]
# TODO 校验sn是否重复
url
=
"https://guide.ssw-htzn.com/business_web/power/delete_power_no"
headers
=
{
"Authorization"
:
token
,
"platform"
:
"business_web"
}
data
=
{
"power_no"
:
sn
[
2
:]}
# json_data = json.dumps(data, ensure_ascii=False)
# result = requests.post(url=url, data=json_data.encode('utf-8'), headers=headers, verify=None)
result
=
requests
.
post
(
url
=
url
,
json
=
data
,
headers
=
headers
)
# print(result.text)
result
=
json
.
loads
(
result
.
text
)
if
int
(
result
[
"error_code"
])
!=
0
:
emit
(
'delete_sn'
,
{
'data'
:
None
,
'error_code'
:
1010
,
'error_message'
:
'sn数据删除失败,请重试!'
})
return
hcontext
=
self
.
scard
.
establish_context
()
result
=
self
.
scard
.
find_self_reader
(
hcontext
)
if
not
result
:
emit
(
'delete_all'
,
{
'data'
:
None
,
'error_code'
:
1001
,
'error_message'
:
'读卡器连接失败, reader connect error'
})
return
emit
(
'delete_sn'
,
{
'data'
:
None
,
'error_code'
:
1011
,
'error_message'
:
'读卡器连接失败, reader connect error'
})
# 写入全为0的sn
write_command
=
[
0xFF
,
0xD6
,
0x00
,
17
,
0x10
]
write_command
+=
[
0
for
i
in
range
(
16
)]
result
=
self
.
scard
.
card_transmit
(
hcontext
,
self
.
scard
.
reader
,
write_command
)
...
...
@@ -583,37 +605,20 @@ class MyNamespace(Namespace):
if
return_code
[
0
]
==
144
and
return_code
[
1
]
==
0
:
pass
else
:
emit
(
'delete_
all
'
,
{
'data'
:
None
,
'error_code'
:
10
07
,
emit
(
'delete_
sn
'
,
{
'data'
:
None
,
'error_code'
:
10
12
,
'error_message'
:
'删除sn数据失败,请重试, write repair data error'
})
return
# 写入全为0的维修数据
for
i
in
range
(
5
):
write_command
=
[
0xFF
,
0xD6
,
0x00
,
10
+
i
,
0x10
]
write_command
+=
[
0
for
x
in
range
(
16
)]
result
=
self
.
scard
.
card_transmit
(
hcontext
,
self
.
scard
.
reader
,
write_command
)
return_code
=
result
[
-
2
:]
if
return_code
[
0
]
==
144
and
return_code
[
1
]
==
0
:
pass
else
:
emit
(
'delete_all'
,
{
'data'
:
None
,
'error_code'
:
1006
,
'error_message'
:
'删除维修数据失败,请重试, write repair data error'
})
return
emit
(
'delete_all'
,
emit
(
'delete_sn'
,
{
'data'
:
None
,
'error_code'
:
0
,
'error_message'
:
'success'
})
except
error
as
e
:
# logger.info(e)
emit
(
'delete_all'
,
{
'data'
:
None
,
'error_code'
:
1009
,
'error_message'
:
'unkwon error, 删除数据,未知错误'
})
pass
finally
:
hresult
=
self
.
scard
.
release_context
(
hcontext
)
# logger.info('Released context.')
def
on_delete_all
(
self
,
message
):
try
:
hcontext
=
None
...
...
@@ -700,4 +705,4 @@ if __name__ == '__main__':
print
(
'程序启动中....'
)
time
.
sleep
(
1
)
print
(
'程序已启动....'
)
socketio
.
run
(
app
,
host
=
'127.0.0.1'
,
port
=
5000
)
socketio
.
run
(
app
,
host
=
'127.0.0.1'
,
port
=
5000
,
debug
=
True
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment