123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #!/usr/bin/python
- # -*- coding: UTF-8 -*-
- #
- #
- # author: Scott Chen
- # date: 2019-12-23
- import datetime
- from django.views.decorators.http import require_http_methods
- from django.http import JsonResponse
- from apps.limit.biz.id_card_reader import IdCarReader
- from apps.limit.biz.year_limit_query import YearLimitQuery
- @require_http_methods(["GET", "POST"])
- def limit(request):
- # response = {}
- # data = {}
- # data['name'] = '张三'
- # data['id_no'] = '443xxxxxxxxxxx32x7'
- # data['total_amount'] = 100000
- # data['innerbalance'] = 3210.01
- #
- # response['code'] = '0'
- # response['msg'] = '成功'
- # response['rows'] = [{'total': 1, 'data': data}]
- # return JsonResponse(response)
- response = {}
- data = {}
- start = datetime.datetime.now()
- print(str(start))
- # 身份证信息读取
- reader = IdCarReader()
- id_car_info = reader.recognize()
- if 'error' in id_car_info:
- response['code'] = '-1'
- response['msg'] = id_car_info['error']
- response['rows'] = [{'total': 0, 'data': []}]
- return JsonResponse(response)
- name, id_no = id_car_info['name'], id_car_info['id_no']
- # 跨境额度查询
- yq = YearLimitQuery(name, id_no)
- year_limit_map = yq.query()
- if 'error' in year_limit_map:
- response['code'] = '-1'
- response['msg'] = year_limit_map['error']
- response['rows'] = [{'total': 0, 'data': []}]
- return JsonResponse(response)
- data['name'] = name
- data['id_no'] = "{0}***********{1}".format(id_no[:4], id_no[-3:])
- data['total_amount'] = year_limit_map['totalAmount']
- data['innerbalance'] = year_limit_map['innerbalance']
- response['code'] = '0'
- response['msg'] = '成功'
- response['rows'] = [{'total': 1, 'data': data}]
- end = datetime.datetime.now()
- print(str(end))
- print(end - start)
- return JsonResponse(response)
|