-
Notifications
You must be signed in to change notification settings - Fork 6
/
__init__.py
68 lines (58 loc) · 2.01 KB
/
__init__.py
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
#!/usr/bin/env python
# encoding: utf-8
import logging
import json
import os
import urlparse
from suds.client import Client
import xmltodict
MAX_CHECK_COUNT = 5
logger = logging.getLogger(__name__)
_current_path = os.path.dirname(os.path.realpath(__file__))
_wsdl = os.path.join(_current_path, 'NciicServices.wsdl')
_url = urlparse.urljoin('file://', _wsdl)
_inlicense = r'shouquanwenjianneirong' # 授权文件字符串
_client = Client(_url)
def _init_inconditions(dict_data):
rows = {
"ROWS": {
"INFO": {"SBM": u"机构名称"},
"ROW": [
{"GMSFHM": u"公民身份号码",
"XM": u"姓名"},
{"GMSFHM": dict_data['id_number'],
"XM": dict_data['name'],
"@FSD": u'location',
"@YWLX": 'test'}
]
}
}
return xmltodict.unparse(rows)
def _parse_result(resp_xml):
result = xmltodict.parse(resp_xml, encoding='utf-8')
if 'RESPONSE' in result:
error_xml = json.dumps(result['RESPONSE'], ensure_ascii=False)
logger.error('NciicServiceError:' + error_xml)
raise('NCIIC_SERVICE_ERROR', error_xml)
else:
row = result['ROWS']['ROW']
items = row['OUTPUT']['ITEM']
if 'gmsfhm' in items[0]:
if items[0]['result_gmsfhm'] == items[1]['result_xm']:
return True
else:
logger.info('CERTIFY_FAILED:' +
json.dumps(row, ensure_ascii=False))
return False
elif 'errormesage' in items[0]:
# 我真不想吐槽这个mesage单词了
logger.info('CERTIFY_FAILED:' +
json.dumps(row, ensure_ascii=False))
return False
def nciic_check(dict_data):
'''dict_data = {'id_number': <id_number>, 'name': <name>}
return: True/False
'''
incondition = _init_inconditions(dict_data)
resp_xml = _client.service.nciicCheck(_inlicense, incondition)
return _parse_result(resp_xml)