main.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import requests
  2. import json
  3. from common.esigntool.esign_config import Config
  4. from common.esigntool.esign_algorithm import buildSignJsonHeader
  5. import time
  6. from datetime import datetime
  7. config = Config()
  8. def get_auth_flow_id():
  9. """获取机构认证&授权页面链接"""
  10. api_path = "/v3/org-auth-url"
  11. method = "POST"
  12. body = {
  13. "clientType": "ALL",
  14. "redirectConfig": {
  15. "redirectUrl": "https://www.baidu.com"
  16. },
  17. "orgAuthConfig": {
  18. "orgId": config.ordid,
  19. }
  20. }
  21. # 签名使用原始字典,内部会统一 json.dumps(去空格),再用完全一致的字符串发送
  22. json_headers = buildSignJsonHeader(config.appId, config.scert, method, api_path, body=body)
  23. body_json = json.dumps(body, separators=(",", ":"), ensure_ascii=False)
  24. resp = requests.request(method, config.host + api_path, data=body_json, headers=json_headers)
  25. print(resp.text)
  26. return resp.text
  27. # get_auth_flow_id()
  28. def get_template_detail():
  29. """查询合同模板中控件详情"""
  30. api_path = f"/v3/doc-templates/{config.templates_id}"
  31. method = "GET"
  32. json_headers = buildSignJsonHeader(config.appId, config.scert, method, api_path)
  33. resp = requests.request(method, config.host + api_path, headers=json_headers)
  34. print(resp.text)
  35. def fill_in_template():
  36. """填写模板生成文件"""
  37. api_path = "/v3/files/create-by-doc-template"
  38. method = "POST"
  39. body = {
  40. "docTemplateId": config.templates_id,
  41. "fileName": "U店在这-商户入驻协议",
  42. "components": [
  43. {
  44. "componentKey": "alien_name",
  45. "componentValue": "爱丽恩严(大连)商务科技有限公司"
  46. },
  47. {
  48. "componentKey": "store_name",
  49. "componentValue": "潘子"
  50. },
  51. {
  52. "componentKey": "date",
  53. "componentValue": datetime.now().strftime("%Y年%m月%d日")
  54. }
  55. ]
  56. }
  57. json_headers = buildSignJsonHeader(config.appId, config.scert, method, api_path, body=body)
  58. body_json = json.dumps(body, separators=(",", ":"), ensure_ascii=False)
  59. resp = requests.request(method, config.host + api_path, data=body_json, headers=json_headers)
  60. print(resp.text)
  61. return resp.text