gatewayController.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. """
  3. @Time : 2022/5/9 10:51
  4. @Auth : Locky
  5. @File :gatewayController.py
  6. @IDE :PyCharm
  7. """
  8. from django.views.generic.base import View
  9. from Object.ResponseObject import ResponseObject
  10. class GatewayView(View):
  11. def get(self, request, *args, **kwargs):
  12. request.encoding = 'utf-8'
  13. operation = kwargs.get('operation')
  14. return self.validation(request.GET, request, operation)
  15. def post(self, request, *args, **kwargs):
  16. request.encoding = 'utf-8'
  17. operation = kwargs.get('operation')
  18. return self.validation(request.POST, request, operation)
  19. def validation(self, request_dict, request, operation):
  20. response = ResponseObject()
  21. if operation == 'gatewayPush': # 网关推送
  22. return self.gatewayPush(request_dict, response)
  23. else:
  24. return response.json(414)
  25. def gatewayPush(self, request_dict, response):
  26. serial_number = request_dict.get('serial_number', None)
  27. try:
  28. return response.json(0)
  29. except Exception as e:
  30. return response.json(500, repr(e))