8ed708b2 by 冯轩

Merge branch 'feature/CHINARPA-3964' into feature/uat-tmp

2 parents 7e5f7786 b81daff4
...@@ -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)
...@@ -82,7 +84,11 @@ class ECM: ...@@ -82,7 +84,11 @@ class ECM:
82 return self.oauth_token 84 return self.oauth_token
83 85
84 def get_headers(self): 86 def get_headers(self):
85 return {'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token())} 87 return {
88 'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token()),
89 'client_id': conf.ECM_OAUTH_ID,
90 'client_secret': conf.ECM_OAUTH_SECRET
91 }
86 92
87 def download(self, save_path, object_id, document_scheme, business_type): 93 def download(self, save_path, object_id, document_scheme, business_type):
88 doc_type, _, _ = self.doc_type_map.get(document_scheme) 94 doc_type, _, _ = self.doc_type_map.get(document_scheme)
...@@ -93,7 +99,9 @@ class ECM: ...@@ -93,7 +99,9 @@ class ECM:
93 "documentType": doc_type, 99 "documentType": doc_type,
94 "objectId": object_id, 100 "objectId": object_id,
95 } 101 }
96 response = requests.post(self.download_url, headers=self.get_headers(), json=download_json, verify=False) 102 header_info = self.get_headers()
103 self.running_log.info("{0} download header_info:{1}".format(self.log_base, header_info))
104 response = requests.post(self.download_url, headers=header_info, json=download_json, verify=False)
97 if response.status_code != 200: 105 if response.status_code != 200:
98 raise ECMException('ECM download failed with code: {0}'.format(response.status_code)) 106 raise ECMException('ECM download failed with code: {0}'.format(response.status_code))
99 base64_data = response.json().get('Envelope', {}).get('Body', {}).get('getResponse', {}).get('return', {}).get( 107 base64_data = response.json().get('Envelope', {}).get('Body', {}).get('getResponse', {}).get('return', {}).get(
...@@ -139,7 +147,9 @@ class ECM: ...@@ -139,7 +147,9 @@ class ECM:
139 # 获取解码后的base64值 147 # 获取解码后的base64值
140 file_data = base64_data.decode() 148 file_data = base64_data.decode()
141 args['file_base64_content'] = file_data 149 args['file_base64_content'] = file_data
142 response = requests.post(self.upload_url, headers=self.get_headers(), json=args, verify=False) 150 header_info = self.get_headers()
151 self.running_log.info("{0} upload header_info:{1}".format(self.log_base, header_info))
152 response = requests.post(self.upload_url, headers=header_info, json=args, verify=False)
143 if response.status_code != 200: 153 if response.status_code != 200:
144 raise ECMException('ECM upload failed with code: {0} , with headers: {1} , with content: {2}'.format( 154 raise ECMException('ECM upload failed with code: {0} , with headers: {1} , with content: {2}'.format(
145 response.status_code, response.headers, response.text)) 155 response.status_code, response.headers, response.text))
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!