views.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. #
  5. # author: Scott Chen
  6. # date: 2019-12-23
  7. import datetime
  8. from django.views.decorators.http import require_http_methods
  9. from django.http import JsonResponse
  10. from apps.limit.biz.id_card_reader import IdCarReader
  11. from apps.limit.biz.year_limit_query import YearLimitQuery
  12. @require_http_methods(["GET", "POST"])
  13. def limit(request):
  14. # response = {}
  15. # data = {}
  16. # data['name'] = '张三'
  17. # data['id_no'] = '443xxxxxxxxxxx32x7'
  18. # data['total_amount'] = 100000
  19. # data['innerbalance'] = 3210.01
  20. #
  21. # response['code'] = '0'
  22. # response['msg'] = '成功'
  23. # response['rows'] = [{'total': 1, 'data': data}]
  24. # return JsonResponse(response)
  25. response = {}
  26. data = {}
  27. start = datetime.datetime.now()
  28. print(str(start))
  29. # 身份证信息读取
  30. reader = IdCarReader()
  31. id_car_info = reader.recognize()
  32. if 'error' in id_car_info:
  33. response['code'] = '-1'
  34. response['msg'] = id_car_info['error']
  35. response['rows'] = [{'total': 0, 'data': []}]
  36. return JsonResponse(response)
  37. name, id_no = id_car_info['name'], id_car_info['id_no']
  38. # 跨境额度查询
  39. yq = YearLimitQuery(name, id_no)
  40. year_limit_map = yq.query()
  41. if 'error' in year_limit_map:
  42. response['code'] = '-1'
  43. response['msg'] = year_limit_map['error']
  44. response['rows'] = [{'total': 0, 'data': []}]
  45. return JsonResponse(response)
  46. data['name'] = name
  47. data['id_no'] = "{0}***********{1}".format(id_no[:4], id_no[-3:])
  48. data['total_amount'] = year_limit_map['totalAmount']
  49. data['innerbalance'] = year_limit_map['innerbalance']
  50. response['code'] = '0'
  51. response['msg'] = '成功'
  52. response['rows'] = [{'total': 1, 'data': data}]
  53. end = datetime.datetime.now()
  54. print(str(end))
  55. print(end - start)
  56. return JsonResponse(response)