gcap.py
5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import requests
from requests.auth import HTTPBasicAuth
from settings import conf
from common.tools.dict_to_xml import dicttoxml, escape_xml
from apps.doc import consts
from apps.doc.exceptions import GCAPException
from collections import OrderedDict
class GCAP:
def __init__(self):
self.url = conf.GCAP_URL
self.headers = {
'Content-Type': 'text/plain',
}
self.auth = HTTPBasicAuth(conf.GCAP_AUTH_USER, conf.GCAP_AUTH_PWD)
@staticmethod
def dict_to_xml(comparison_res):
comparison_xml = dicttoxml(comparison_res, root=False, attr_type=False)
return consts.BASE_XML_TEXT.format(consts.CDATA_TEXT.format(escape_xml(comparison_xml))).encode('utf-8')
def send(self, data):
response = requests.post(self.url, headers=self.headers, data=data, verify=False, auth=self.auth)
if response.status_code != 200:
raise GCAPException('GCAP response with code: {0}'.format(response.status_code))
return response.status_code
def test_send(self):
test_res = OrderedDict({
'OCR_Input': {
'uniqSeq': '201809301905121000',
'applicationId': 'CH-B000046340',
'applicationEntity': 'AFC',
'applicationVersion': 3,
'vehicleStatus': 'PCNEW',
'wholeResult': 'Y',
'wholeResultMessage': 'msg',
'applicationLink': 'url1',
'individualCusInfo': [
{
'applicantType': 'COAPP',
'idType': 'ITARI',
'customerType': 'TCDAS',
'customerChineseName': 'co-app-name',
'idNum': 'idNum',
'idExpiryDate': '2020-02-02T15:52:18.1049637+08:00',
'dateOfBirth': '2020-02-02T15:52:18.1049637+08:00',
'customerChineseNameResult': 'Y',
'idNumResult': 'Y',
'secondIdNumResult': 'Y',
'idExpiryDateResult': 'Y',
'dateOfBirthResult': 'Y',
},
{
'applicantType': 'GAUTR1',
'idType': 'ITPSP',
'customerType': 'TCDAS',
'customerChineseName': 'ga1-name',
'idNum': 'id3',
'idExpiryDate': '2020-03-03T15:52:18.1049637+08:00',
'dateOfBirth': '2020-03-03T15:52:18.1049637+08:00',
'customerChineseNameResult': 'Y',
'idNumResult': 'Y',
'secondIdNumResult': 'Y',
'idExpiryDateResult': 'Y',
'dateOfBirthResult': 'Y',
},
{
'applicantType': 'GAUTR2',
'idType': 'ITHKM',
'customerType': 'TCDAS',
'customerChineseName': 'ga2-name',
'idNum': 'id4',
'idExpiryDate': '2020-04-04T15:52:18.1049637+08:00',
'dateOfBirth': '2020-04-04T15:52:18.1049637+08:00',
'customerChineseNameResult': 'Y',
'idNumResult': 'Y',
'secondIdNumResult': 'Y',
'idExpiryDateResult': 'Y',
'dateOfBirthResult': 'Y',
},
],
'usedCarInfo': {
'vinNo': 'LBVSFJSDLFJLSDJF',
'manufactureDate': '2020-09-03T15:52:18.1049637+08:00',
'firstRegistrationDate': '2020-09-03T15:52:18.1049637+08:00',
'vinNoResult': 'Y',
'manufactureDateResult': 'Y',
'firstRegistrationDateResult': 'Y',
},
'corporateCusInfo': {
'customerChineseName': '北京思图场景数据科技服务有限公司',
'legalRepName': '李六',
'idNum': 'MA007438143XJ1P',
'customerType': 'TCCOR',
'businessLicenseNo': 'MA007438143XJ1P',
'taxRegistrationCode': 'MA007438143XJ1P',
'incorporationDate': '2020-09-02T15:52:18.1049637+08:00',
'businessLicenseDueDate': '2020-09-02T15:52:18.1049637+08:00',
'capitalRegAmount': '60000000',
'customerChinessNameResult': 'Y',
'legalRepNameResult': 'Y',
'idNumResult': 'Y',
'businessLicenseNoResult': 'Y',
'taxRegistrationCodeResult': 'Y',
'incorporationDateResult': 'Y',
'businessLicenseDueDateResult': 'Y',
'capitalRegAmountResult': 'Y',
}
}
})
status_code = self.send(self.dict_to_xml(test_res))
print(status_code)
gcap = GCAP()