0c6d8799 by 周伟奇

add MPOS

1 parent e914ba66
...@@ -1407,6 +1407,7 @@ SE_USED_FIELD = ['vinNo', 'vehicleTransactionAmount'] ...@@ -1407,6 +1407,7 @@ SE_USED_FIELD = ['vinNo', 'vehicleTransactionAmount']
1407 SE_NEW_ADD_FIELD = ['customerName', 'idNum', 'dateOfInvoice', 'stamp', '发票联', '发票真伪校验', '新旧版式'] 1407 SE_NEW_ADD_FIELD = ['customerName', 'idNum', 'dateOfInvoice', 'stamp', '发票联', '发票真伪校验', '新旧版式']
1408 SE_FPL_VALUE = '发票联' 1408 SE_FPL_VALUE = '发票联'
1409 SE_STAMP_VALUE = '有' 1409 SE_STAMP_VALUE = '有'
1410 SE_DYSYR_VALUE = '无'
1410 SE_LAYOUT_VALUE = '旧版-旧打印、新版-新打印' 1411 SE_LAYOUT_VALUE = '旧版-旧打印、新版-新打印'
1411 SE_GB_NEW_FIELD = ['vinNo'] 1412 SE_GB_NEW_FIELD = ['vinNo']
1412 SE_GB_USED_FIELD = ['customerName', 'idNum', 'date'] 1413 SE_GB_USED_FIELD = ['customerName', 'idNum', 'date']
...@@ -2226,3 +2227,8 @@ AUTO_WB_FIELD = ( ...@@ -2226,3 +2227,8 @@ AUTO_WB_FIELD = (
2226 'rpa_get_case_from_ocr_time', 'rpa_get_case_from_oc_time', 'rpa_payment_authorize_time', 'rpa_second_eye_time') 2227 'rpa_get_case_from_ocr_time', 'rpa_get_case_from_oc_time', 'rpa_payment_authorize_time', 'rpa_second_eye_time')
2227 ) 2228 )
2228 2229
2230 MPOS_MAP = {
2231 IC_CLASSIFY,
2232 BC_CLASSIFY,
2233 BL_CLASSIFY,
2234 }
......
1 import re 1 import re
2 import json
3 import requests
2 from .named_enum import DocStatus 4 from .named_enum import DocStatus
3 from .models import HILDoc, AFCDoc 5 from .models import HILDoc, AFCDoc
4 from . import consts 6 from . import consts
5 7
6 8
9 class MPOSHandler:
10
11 @staticmethod
12 def ocr1_process(url, img_base64):
13 result_list = []
14 json_data = {
15 "file": img_base64,
16 }
17 ocr_1_response = requests.post(url, json=json_data)
18 if ocr_1_response.status_code != 200:
19 return result_list
20 ocr_1_res = ocr_1_response.json()
21
22 for ocr_data in ocr_1_res.get('data', []):
23
24 license_data = ocr_data.get('data')
25 if not license_data:
26 continue
27
28 if isinstance(license_data, dict):
29 license_data.pop('base64_img', '')
30
31 id_card_dict = {}
32 card_type = license_data.get('type', '')
33 is_ic = card_type.startswith('身份证')
34 is_info_side = card_type.endswith('信息面')
35 # id_card_dict['类别'] = '0' if is_ic else '1'
36 if is_ic:
37 field_map = consts.IC_MAP_0 if is_info_side else consts.IC_MAP_1
38 else:
39 field_map = consts.RP_MAP_0 if is_info_side else consts.RP_MAP_1
40 for write_field, search_field in field_map:
41 id_card_dict[write_field] = license_data.get('words_result', {}).get(search_field, {}).get('words', '')
42 if not is_info_side:
43 start_time = license_data.get('words_result', {}).get('签发日期', {}).get('words', '')
44 end_time = license_data.get('words_result', {}).get('失效日期', {}).get('words', '')
45 id_card_dict['有效期限'] = '{0}-{1}'.format(start_time, end_time)
46 result_list.append(id_card_dict)
47 return result_list
48
49 @staticmethod
50 def ocr2_process(url, classify, img_base64):
51 result_list = []
52 pid, _, _, _, _, _ = consts.LICENSE_CLASSIFY_MAPPING.get(classify)
53 json_data_2 = {
54 "pid": str(pid),
55 "filedata": img_base64
56 }
57 ocr_2_response = requests.post(url, data=json_data_2)
58 if ocr_2_response.status_code != 200:
59 return result_list
60 ocr_2_res = json.loads(ocr_2_response.text)
61
62 if ocr_2_res.get('ErrorCode') in consts.SUCCESS_CODE_SET:
63 if pid == consts.BC_PID:
64 # 银行卡
65 # res_dict = {}
66 # for en_key, chn_key in consts.BC_FIELD:
67 # res_dict[chn_key] = ocr_res_2.get(en_key, '')
68 result_list.append(ocr_2_res)
69 else:
70 # 营业执照等
71 for result_dict in ocr_2_res.get('ResultList', []):
72 res_dict = {}
73 for field_dict in result_dict.get('FieldList', []):
74 res_dict[field_dict.get('chn_key', '')] = field_dict.get('value', '')
75 result_list.append(res_dict)
76 return result_list
77
78
7 class DocHandler: 79 class DocHandler:
8 80
9 @staticmethod 81 @staticmethod
......
1 from django.urls import path
2 from . import views
3
4
5 urlpatterns = [
6 path(r'v1', views.MPOSView.as_view()),
7 ]
...@@ -43,7 +43,7 @@ from .models import ( ...@@ -43,7 +43,7 @@ from .models import (
43 AFCAutoSettlement, 43 AFCAutoSettlement,
44 ) 44 )
45 from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult 45 from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult
46 from .mixins import DocHandler 46 from .mixins import DocHandler, MPOSHandler
47 from . import consts 47 from . import consts
48 from apps.account.authentication import OAuth2AuthenticationWithUser 48 from apps.account.authentication import OAuth2AuthenticationWithUser
49 from celery_compare.tasks import compare 49 from celery_compare.tasks import compare
...@@ -507,6 +507,11 @@ result_update_args = { ...@@ -507,6 +507,11 @@ result_update_args = {
507 'result': fields.List(fields.Nested(result_item_args), required=True, validate=validate.Length(min=1)), 507 'result': fields.List(fields.Nested(result_item_args), required=True, validate=validate.Length(min=1)),
508 } 508 }
509 509
510 mpos_args = {
511 'type': fields.Int(required=True, validate=validate.OneOf(consts.MPOS_MAP.keys())),
512 'file_base64_content': fields.List(fields.Str(), required=True, validate=validate.Length(min=1)),
513 }
514
510 515
511 class UploadDocView(GenericView, DocHandler): 516 class UploadDocView(GenericView, DocHandler):
512 # permission_classes = [] 517 # permission_classes = []
...@@ -1422,3 +1427,23 @@ class AutoSettlementExcelView(GenericView): ...@@ -1422,3 +1427,23 @@ class AutoSettlementExcelView(GenericView):
1422 wb.close() 1427 wb.close()
1423 file_name = 'cr_auto_records_{0}'.format(timezone.now().strftime('%Y-%m-%d_%H:%M:%S')) 1428 file_name = 'cr_auto_records_{0}'.format(timezone.now().strftime('%Y-%m-%d_%H:%M:%S'))
1424 return response.excel_response(file_name, io_content) 1429 return response.excel_response(file_name, io_content)
1430
1431
1432 class MPOSView(GenericView, MPOSHandler):
1433 permission_classes = [IsAuthenticated]
1434 authentication_classes = [OAuth2AuthenticationWithUser]
1435
1436 # MPOS
1437 @use_args(mpos_args, location='data')
1438 def post(self, request, args):
1439 classify = args.get('type')
1440 result_list = []
1441 for img_base64 in args.get('file_base64_content', []):
1442 if classify in consts.LICENSE_CLASSIFY_SET_1:
1443 result = self.ocr1_process(conf.MPOS_URL1, img_base64)
1444 else:
1445 result = self.ocr2_process(conf.MPOS_URL2, classify, img_base64)
1446
1447 result_list.extend(result)
1448
1449 return response.ok(data=result_list)
......
...@@ -23,5 +23,6 @@ urlpatterns = [ ...@@ -23,5 +23,6 @@ urlpatterns = [
23 path(r'api/priority/', include('apps.doc.priority_urls')), 23 path(r'api/priority/', include('apps.doc.priority_urls')),
24 path(r'api/compare/', include('apps.doc.compare_urls')), 24 path(r'api/compare/', include('apps.doc.compare_urls')),
25 path(r'api/doc/', include('apps.doc.internal_urls')), 25 path(r'api/doc/', include('apps.doc.internal_urls')),
26 path(r'api/mpos/', include('apps.doc.mpos_urls')),
26 path('api/oauth/', include('oauth2_provider.urls', namespace='oauth2_provider')), 27 path('api/oauth/', include('oauth2_provider.urls', namespace='oauth2_provider')),
27 ] 28 ]
......
...@@ -1194,7 +1194,7 @@ def get_se_cms_compare_info_auto(last_obj, application_entity): ...@@ -1194,7 +1194,7 @@ def get_se_cms_compare_info_auto(last_obj, application_entity):
1194 # (consts.SE_BD_FIELD[6], cms_info.get('insuranceDetails', {}).get('startDate', '')), 1194 # (consts.SE_BD_FIELD[6], cms_info.get('insuranceDetails', {}).get('startDate', '')),
1195 # (consts.SE_BD_FIELD[7], cms_info.get('insuranceDetails', {}).get('endDate', '')), 1195 # (consts.SE_BD_FIELD[7], cms_info.get('insuranceDetails', {}).get('endDate', '')),
1196 # (consts.SE_BD_FIELD[8], consts.SE_STAMP_VALUE), 1196 # (consts.SE_BD_FIELD[8], consts.SE_STAMP_VALUE),
1197 # (consts.SE_BD_FIELD[9], consts.SE_STAMP_VALUE), 1197 # (consts.SE_BD_FIELD[9], consts.SE_DYSYR_VALUE),
1198 # ] 1198 # ]
1199 # if is_insurance == 1: 1199 # if is_insurance == 1:
1200 # bd_field_input.append((consts.SE_BD_FIELD[10], insurance_price)) 1200 # bd_field_input.append((consts.SE_BD_FIELD[10], insurance_price))
...@@ -1677,7 +1677,7 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list): ...@@ -1677,7 +1677,7 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
1677 (consts.SE_BD_FIELD[6], cms_info.get('insuranceDetails', {}).get('startDate', '')), 1677 (consts.SE_BD_FIELD[6], cms_info.get('insuranceDetails', {}).get('startDate', '')),
1678 (consts.SE_BD_FIELD[7], cms_info.get('insuranceDetails', {}).get('endDate', '')), 1678 (consts.SE_BD_FIELD[7], cms_info.get('insuranceDetails', {}).get('endDate', '')),
1679 (consts.SE_BD_FIELD[8], consts.SE_STAMP_VALUE), 1679 (consts.SE_BD_FIELD[8], consts.SE_STAMP_VALUE),
1680 (consts.SE_BD_FIELD[9], consts.SE_STAMP_VALUE), 1680 (consts.SE_BD_FIELD[9], consts.SE_DYSYR_VALUE),
1681 ] 1681 ]
1682 if is_insurance == 1: 1682 if is_insurance == 1:
1683 bd_field_input.append((consts.SE_BD_FIELD[10], insurance_price)) 1683 bd_field_input.append((consts.SE_BD_FIELD[10], insurance_price))
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!