MOD:ecm上传下载接口
Showing
1 changed file
with
14 additions
and
4 deletions
... | @@ -5,9 +5,10 @@ import requests | ... | @@ -5,9 +5,10 @@ import requests |
5 | from common.redis_cache import redis_handler as rh | 5 | from common.redis_cache import redis_handler as rh |
6 | from settings import conf | 6 | from settings import conf |
7 | from apps.doc.exceptions import ECMException | 7 | from apps.doc.exceptions import ECMException |
8 | from common.mixins import GenericView | ||
8 | 9 | ||
9 | 10 | ||
10 | class ECM: | 11 | class ECM(GenericView): |
11 | 12 | ||
12 | def __init__(self): | 13 | def __init__(self): |
13 | self.oauth_token = None | 14 | self.oauth_token = None |
... | @@ -53,6 +54,7 @@ class ECM: | ... | @@ -53,6 +54,7 @@ class ECM: |
53 | "b_frontend_partner", "b_dealer_code", "b_dealer_name", "b_comment", | 54 | "b_frontend_partner", "b_dealer_code", "b_dealer_name", "b_comment", |
54 | "b_contract_no", "b_location", "b_company_name", "b_certificate_code", "b_vin", | 55 | "b_contract_no", "b_location", "b_company_name", "b_certificate_code", "b_vin", |
55 | "b_registration_no", "b_F2I_name"] | 56 | "b_registration_no", "b_F2I_name"] |
57 | self.log_base = '[ecm]' | ||
56 | 58 | ||
57 | def update_oauth_token(self): | 59 | def update_oauth_token(self): |
58 | response = requests.post(self.oauth_url, headers=self.oauth_headers, data=self.oauth_payload, verify=False) | 60 | response = requests.post(self.oauth_url, headers=self.oauth_headers, data=self.oauth_payload, verify=False) |
... | @@ -81,7 +83,11 @@ class ECM: | ... | @@ -81,7 +83,11 @@ class ECM: |
81 | return self.oauth_token | 83 | return self.oauth_token |
82 | 84 | ||
83 | def get_headers(self): | 85 | def get_headers(self): |
84 | return {'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token())} | 86 | return { |
87 | 'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token()), | ||
88 | 'client_id': conf.ECM_OAUTH_ID, | ||
89 | 'client_secret': conf.ECM_OAUTH_SECRET | ||
90 | } | ||
85 | 91 | ||
86 | def download(self, save_path, object_id, document_scheme, business_type): | 92 | def download(self, save_path, object_id, document_scheme, business_type): |
87 | doc_type, _, _ = self.doc_type_map.get(document_scheme) | 93 | doc_type, _, _ = self.doc_type_map.get(document_scheme) |
... | @@ -92,7 +98,9 @@ class ECM: | ... | @@ -92,7 +98,9 @@ class ECM: |
92 | "documentType": doc_type, | 98 | "documentType": doc_type, |
93 | "objectId": object_id, | 99 | "objectId": object_id, |
94 | } | 100 | } |
95 | response = requests.post(self.download_url, headers=self.get_headers(), json=download_json, verify=False) | 101 | header_info = self.get_headers() |
102 | self.running_log.info("{0} download header_info:{1}".format(self.log_base, header_info)) | ||
103 | response = requests.post(self.download_url, headers=header_info, json=download_json, verify=False) | ||
96 | if response.status_code != 200: | 104 | if response.status_code != 200: |
97 | raise ECMException('ECM download failed with code: {0}'.format(response.status_code)) | 105 | raise ECMException('ECM download failed with code: {0}'.format(response.status_code)) |
98 | base64_data = response.json().get('Envelope', {}).get('Body', {}).get('getResponse', {}).get('return', {}).get( | 106 | base64_data = response.json().get('Envelope', {}).get('Body', {}).get('getResponse', {}).get('return', {}).get( |
... | @@ -138,7 +146,9 @@ class ECM: | ... | @@ -138,7 +146,9 @@ class ECM: |
138 | # 获取解码后的base64值 | 146 | # 获取解码后的base64值 |
139 | file_data = base64_data.decode() | 147 | file_data = base64_data.decode() |
140 | args['file_base64_content'] = file_data | 148 | args['file_base64_content'] = file_data |
141 | response = requests.post(self.upload_url, headers=self.get_headers(), json=args, verify=False) | 149 | header_info = self.get_headers() |
150 | self.running_log.info("{0} upload header_info:{1}".format(self.log_base, header_info)) | ||
151 | response = requests.post(self.upload_url, headers=header_info, json=args, verify=False) | ||
142 | if response.status_code != 200: | 152 | if response.status_code != 200: |
143 | raise ECMException('ECM upload failed with code: {0} , with headers: {1} , with content: {2}'.format( | 153 | raise ECMException('ECM upload failed with code: {0} , with headers: {1} , with content: {2}'.format( |
144 | response.status_code, response.headers, response.text)) | 154 | response.status_code, response.headers, response.text)) | ... | ... |
-
Please register or sign in to post a comment