WXTechController.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # -*- encoding: utf-8 -*-
  2. """
  3. @File : WXTechController.py
  4. @Time : 2023/5/6 16:40
  5. @Author : stephen
  6. @Email : zhangdongming@asj6.wecom.work
  7. @Software: PyCharm
  8. """
  9. from django.http import QueryDict
  10. from django.views import View
  11. from Ansjer.config import LOGGER
  12. from Object.ResponseObject import ResponseObject
  13. from Object.TokenObject import TokenObject
  14. from Object.WXTechObject import WXTechObject
  15. class WXTechController(View):
  16. class SmartSocketView(View):
  17. def get(self, request, *args, **kwargs):
  18. request.encoding = 'utf-8'
  19. operation = kwargs.get('operation')
  20. return self.validation(request.GET, request, operation)
  21. def post(self, request, *args, **kwargs):
  22. request.encoding = 'utf-8'
  23. operation = kwargs.get('operation')
  24. return self.validation(request.POST, request, operation)
  25. def delete(self, request, *args, **kwargs):
  26. request.encoding = 'utf-8'
  27. operation = kwargs.get('operation')
  28. delete = QueryDict(request.body)
  29. if not delete:
  30. delete = request.GET
  31. return self.validation(delete, request, operation)
  32. def put(self, request, *args, **kwargs):
  33. request.encoding = 'utf-8'
  34. operation = kwargs.get('operation')
  35. put = QueryDict(request.body)
  36. return self.validation(put, request, operation)
  37. def validation(self, request_dict, request, operation):
  38. token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
  39. lang = request_dict.get('lang', token.lang)
  40. response = ResponseObject(lang)
  41. if token.code != 0:
  42. return response.json(token.code)
  43. if operation == 'getCardsInfo':
  44. return self.get_cards_info(request_dict, response)
  45. @classmethod
  46. def get_cards_info(cls, request_dict, response):
  47. """
  48. 五兴单卡获取信息
  49. """
  50. try:
  51. iccid = request_dict.get('iccid', None)
  52. operator = int(request_dict.get('operator', 3))
  53. LOGGER.info('*****WXTechController.get_cards_info:iccid:{},operator:{}'.format(iccid, operator))
  54. if not iccid:
  55. return response.json(444)
  56. data = {'iccid': iccid, 'operator': operator}
  57. wx_tech = WXTechObject()
  58. return response.json(0, wx_tech.get_cards_info(**data))
  59. except Exception as e:
  60. LOGGER.info('*****WXTechController.get_cards_info:errLine:{}, errMsg:{}'
  61. .format(e.__traceback__.tb_lineno, repr(e)))
  62. return response.json(500, repr(e))