| @@ -6,6 +6,7 @@ from django_response import response | ||
| 6 | 6 |  | 
| 7 | 7 | from apps.contract.models import LensmanContributionContractInfo | 
| 8 | 8 | from kodo.decorators import check_admin | 
| 9 | +from utils.tencentcloud.ess import describe_file_urls | |
| 9 | 10 |  | 
| 10 | 11 |  | 
| 11 | 12 | @logit(res=True) | 
| @@ -16,17 +17,8 @@ def get_signed_contribtion_contract_file_api(request, administrator): | ||
| 16 | 17 |  | 
| 17 | 18 | contract = LensmanContributionContractInfo.objects.filter(contribution_id=contribution_id, user_id=user_id).first() | 
| 18 | 19 |  | 
| 19 | -    operator = { | |
| 20 | - "UserId": settings.CONTRACT_LENSMAN_CONTRIBUTION_OPERATOR_ID | |
| 21 | - } | |
| 22 | - | |
| 23 | - BusinessType = 'FLOW' | |
| 24 | - BusinessIds = [contract.flow_id] | |
| 25 | - FileType = 'PDF' | |
| 26 | - UrlTtl = '86400' # 过期时间 | |
| 27 | - | |
| 28 | - # TODO: 获取合同文件 https://qian.tencent.com/developers/companyApis/templatesAndFiles/DescribeFileUrls | |
| 29 | - FileUrls = [] | |
| 20 | + describe_file_urls_result = describe_file_urls(business_id=contract.flow_id) | |
| 21 | + FileUrls = describe_file_urls_result.FileUrls | |
| 30 | 22 |  | 
| 31 | 23 |      return response(200, data={ | 
| 32 | 24 | 'file_url': FileUrls[0].Url | 
| @@ -335,3 +335,61 @@ def callback_decode(data, encryption_key=None): | ||
| 335 | 335 | # print(e) | 
| 336 | 336 | # print(str(e, encoding="utf8")) | 
| 337 | 337 | return json.loads(e) | 
| 338 | + | |
| 339 | + | |
| 340 | +def test_describe_file_urls(): | |
| 341 | +    # { | |
| 342 | + # "TotalCount": 1, | |
| 343 | + # "FileUrls": [ | |
| 344 | +    #         { | |
| 345 | + # "Url": "https://file.ess.tencent.cn/file/FLOW/yDCHQUU0q7lli4UxZZqK9EJQBXolGmKl/0/0.PDF?hkey=2224d95a960e5bc7e6e3686cff314349ca93867dbd0b1eca01ba63991c8bd8e9c479977410d668b7b3d5bf14af059f969ce4644cf43a7cb6395601a042cadd33a56be20d1643070aa660af450d0ee0b6e30758030e2c0cbd2276bd1d4f05c818", | |
| 346 | + # "Option": "[\"595.30,841.90\",\"-1\"]" | |
| 347 | + # } | |
| 348 | + # ], | |
| 349 | + # "RequestId": "e9381020-c673-4ea6-b051-3a64b0e8a821" | |
| 350 | + # } | |
| 351 | + business_id = 'yDCHQUU0q7lli4UxZZqK9EJQBXolGmKl' | |
| 352 | + return describe_file_urls(business_id=business_id) | |
| 353 | + | |
| 354 | + | |
| 355 | +def describe_file_urls(business_type='FLOW', business_id=None, business_ids=None, file_type='PDF', url_ttl=86400): | |
| 356 | + # https://qian.tencent.com/developers/companyApis/templatesAndFiles/DescribeFileUrls/ | |
| 357 | + try: | |
| 358 | + # 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密 | |
| 359 | + # 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305 | |
| 360 | + # 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 | |
| 361 | + cred = credential.Credential(secret_id, secret_key) | |
| 362 | + # 实例化一个http选项,可选的,没有特殊需求可以跳过 | |
| 363 | + httpProfile = HttpProfile() | |
| 364 | + httpProfile.endpoint = endpoint | |
| 365 | + | |
| 366 | + # 实例化一个client选项,可选的,没有特殊需求可以跳过 | |
| 367 | + clientProfile = ClientProfile() | |
| 368 | + clientProfile.httpProfile = httpProfile | |
| 369 | + # 实例化要请求产品的client对象,clientProfile是可选的 | |
| 370 | + client = ess_client.EssClient(cred, "", clientProfile) | |
| 371 | + | |
| 372 | + # 实例化一个请求对象,每个接口都会对应一个request对象 | |
| 373 | + req = models.DescribeFileUrlsRequest() | |
| 374 | + business_ids = business_ids or [business_id] | |
| 375 | +        params = { | |
| 376 | +            "Operator": { | |
| 377 | + "UserId": operator_id | |
| 378 | + }, | |
| 379 | + "BusinessType": business_type, | |
| 380 | + "BusinessIds": business_ids, | |
| 381 | + "FileType": file_type, | |
| 382 | + "UrlTtl": url_ttl, | |
| 383 | + } | |
| 384 | + req.from_json_string(json.dumps(params)) | |
| 385 | + | |
| 386 | + # 返回的resp是一个DescribeFlowTemplatesResponse的实例,与请求对象对应 | |
| 387 | + resp = client.DescribeFileUrls(req) | |
| 388 | + # 输出json格式的字符串回包 | |
| 389 | + # print(resp.to_json_string()) | |
| 390 | + | |
| 391 | + except TencentCloudSDKException as err: | |
| 392 | + print(err) | |
| 393 | +        resp = {} | |
| 394 | + | |
| 395 | + return resp |