b81daff4 by 冯轩

MOD:ecm上传下载接口

1 parent 3d633024
......@@ -5,9 +5,10 @@ import requests
from common.redis_cache import redis_handler as rh
from settings import conf
from apps.doc.exceptions import ECMException
from common.mixins import GenericView
class ECM:
class ECM(GenericView):
def __init__(self):
self.oauth_token = None
......@@ -53,6 +54,7 @@ class ECM:
"b_frontend_partner", "b_dealer_code", "b_dealer_name", "b_comment",
"b_contract_no", "b_location", "b_company_name", "b_certificate_code", "b_vin",
"b_registration_no", "b_F2I_name"]
self.log_base = '[ecm]'
def update_oauth_token(self):
response = requests.post(self.oauth_url, headers=self.oauth_headers, data=self.oauth_payload, verify=False)
......@@ -81,7 +83,11 @@ class ECM:
return self.oauth_token
def get_headers(self):
return {'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token())}
return {
'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token()),
'client_id': conf.ECM_OAUTH_ID,
'client_secret': conf.ECM_OAUTH_SECRET
}
def download(self, save_path, object_id, document_scheme, business_type):
doc_type, _, _ = self.doc_type_map.get(document_scheme)
......@@ -92,7 +98,9 @@ class ECM:
"documentType": doc_type,
"objectId": object_id,
}
response = requests.post(self.download_url, headers=self.get_headers(), json=download_json, verify=False)
header_info = self.get_headers()
self.running_log.info("{0} download header_info:{1}".format(self.log_base, header_info))
response = requests.post(self.download_url, headers=header_info, json=download_json, verify=False)
if response.status_code != 200:
raise ECMException('ECM download failed with code: {0}'.format(response.status_code))
base64_data = response.json().get('Envelope', {}).get('Body', {}).get('getResponse', {}).get('return', {}).get(
......@@ -138,7 +146,9 @@ class ECM:
# 获取解码后的base64值
file_data = base64_data.decode()
args['file_base64_content'] = file_data
response = requests.post(self.upload_url, headers=self.get_headers(), json=args, verify=False)
header_info = self.get_headers()
self.running_log.info("{0} upload header_info:{1}".format(self.log_base, header_info))
response = requests.post(self.upload_url, headers=header_info, json=args, verify=False)
if response.status_code != 200:
raise ECMException('ECM upload failed with code: {0} , with headers: {1} , with content: {2}'.format(
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!