app.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from flask import Flask, jsonify
  2. from PN532data import readChip
  3. import webbrowser
  4. from threading import Timer
  5. from flask import render_template
  6. from flask_cors import CORS
  7. import string
  8. app = Flask(__name__)
  9. CORS(app, resources=r'/*')
  10. @app.route('/readChip')
  11. def read_chip():
  12. try:
  13. result = readChip()
  14. print(result)
  15. return jsonify({'code': 200, 'msg': '读取成功',
  16. 'data': {'list': result[0], 'chipNumber': result[1], 'vaccinationCipher': result[2],
  17. 'id': result[3]}})
  18. except Exception as e:
  19. print(e)
  20. return jsonify({'code': 500, 'msg': '请见检查芯片是否放好或读卡器连接是否正常'})
  21. @app.route('/')
  22. def index():
  23. return render_template('index.html')
  24. def open_browser():
  25. webbrowser.open_new('http://127.0.0.1:9000')
  26. if __name__ == '__main__':
  27. Timer(1, open_browser).start()
  28. app.run(port=9000, debug=True, host='0.0.0.0')
  29. # str ="\xc1\xf5\xbf\xad\xcf\xc8\xc9\xfa\r\n\xc9\xed\xb8\xdf\xa3\xba"
  30. # str = "this is string example....wow!!!";
  31. #
  32. # print(str.decode('utf-8'))