Преглед изворни кода

fill_in_template():
"""填写模板生成文件"""

mengqiankang пре 2 месеци
родитељ
комит
2b6fc2dd34
35 измењених фајлова са 127 додато и 53 уклоњено
  1. 2 0
      alien_snowflake/README.md
  2. 2 0
      alien_snowflake/__init__.py
  3. 3 3
      alien_store/db/models/contract_store.py
  4. 2 0
      alien_store/repositories/contract_repo.py
  5. 0 1
      common/esigntool/__init__.py
  6. 5 4
      common/esigntool/esign_algorithm.py
  7. 6 2
      common/esigntool/esign_config.py
  8. 14 0
      common/esigntool/esign_templates.py
  9. 0 18
      common/esigntool/esign_tool_info.py
  10. 68 0
      common/esigntool/main.py
  11. 1 1
      common/run/moduledemo/auth/auth_launch.py
  12. 1 1
      common/run/moduledemo/auth/auth_query.py
  13. 1 1
      common/run/moduledemo/fileandtemplate/expand.py
  14. 1 1
      common/run/moduledemo/fileandtemplate/file.py
  15. 1 1
      common/run/moduledemo/fileandtemplate/template.py
  16. 1 1
      common/run/moduledemo/members/org_member.py
  17. 1 1
      common/run/moduledemo/order/order_buy.py
  18. 1 1
      common/run/moduledemo/order/order_query.py
  19. 1 1
      common/run/moduledemo/seal/org_seals.py
  20. 1 1
      common/run/moduledemo/seal/psn_seals.py
  21. 1 1
      common/run/moduledemo/seal/upload_url.py
  22. 1 1
      common/run/moduledemo/sign/attachments_change.py
  23. 1 1
      common/run/moduledemo/sign/copiers_change.py
  24. 1 1
      common/run/moduledemo/sign/signfields_change.py
  25. 1 1
      common/run/moduledemo/sign/signflow_change.py
  26. 1 1
      common/run/moduledemo/sign/signflow_download.py
  27. 1 1
      common/run/moduledemo/sign/signflow_launch.py
  28. 1 1
      common/run/moduledemo/sign/signflow_query.py
  29. 1 1
      common/run/moduledemo/sign/signflow_rescission.py
  30. 1 1
      common/run/scenedome/b2b_autosign_demo.py
  31. 1 1
      common/run/scenedome/b2b_handsign_demo.py
  32. 1 1
      common/run/scenedome/b2c_handsign_demo.py
  33. 1 1
      common/run/scenedome/dynamic_table_demo.py
  34. 1 1
      common/run/scenedome/order_demo.py
  35. 1 1
      common/run/scenedome/signature_check_demo.py

+ 2 - 0
alien_snowflake/README.md

@@ -51,3 +51,5 @@ pk = gen.next_id()
 - 若需更大规模,可扩展 `datacenter_id` / `worker_id` 映射,但需保持各节点唯一性。
 
 
+
+

+ 2 - 0
alien_snowflake/__init__.py

@@ -11,3 +11,5 @@ __all__ = [
     "next_id",
     "resolve_worker_id",
 ]
+
+

+ 3 - 3
alien_store/db/models/contract_store.py

@@ -16,6 +16,6 @@ class ContractStore(Base, AuditMixin):
     merchant_name: Mapped[str] = mapped_column(String(100), comment="商家姓名")
     contact_phone: Mapped[str] = mapped_column(String(20), comment="联系电话")
     signing_status: Mapped[str] = mapped_column(String(20), default="未签署", comment="签署状态(已签署,未签署,已到期)")
-    signing_time: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True, comment="签署时间")
-    effective_time: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True, comment="生效时间")
-    expiry_time: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True, comment="到期时间")
+    contract_url: Mapped[str] = mapped_column(String(255), comment='合同URL')
+    seal_url: Mapped[str] = mapped_column(String(255), comment='印章URL')
+

+ 2 - 0
alien_store/repositories/contract_repo.py

@@ -14,3 +14,5 @@ class ContractRepository:
         """根据店铺id查询所有合同"""
         return self.db.query(ContractStore).filter(ContractStore.id == store_id).all()
 
+
+

+ 0 - 1
common/esigntool/__init__.py

@@ -1,5 +1,4 @@
 from .esign_algorithm import *
 from .esign_emun import *
-from .esign_tool_info import *
 from .esign_file import *
 from .esign_config import *

+ 5 - 4
common/esigntool/esign_algorithm.py

@@ -66,13 +66,14 @@ def doSignatureBase64(message, secret):
     sign = base64.b64encode(hmac.new(key, message, digestmod=sha256).digest()).decode()
     return sign
 
-
 def getMillisecondStamp():
     """
     获取当前毫秒时间戳
     :return:
     """
-    return str(int(time.time() * 1000))
+    # 使用 time_ns 避免浮点精度问题
+    # print(str(time.time_ns() // 1_000_000))
+    return str(time.time_ns() // 1_000_000)
 
 
 def buildHeader(appid, content_md5, req_signature, accept="*/*",
@@ -131,8 +132,8 @@ def buildSignJsonHeader(appid, secret, http_method, url, body=None,
     content_md5 = ""
     # 判断是PUT或者POST请求,不需要计算计算md5,否则md5为空
     if httpMethodEnum.PUT == http_method or httpMethodEnum.POST == http_method:
-        # 字典转json字符串
-        body = json.dumps(body)
+        # 字典转json字符串(去空格,保证与发送一致)
+        body = json.dumps(body, separators=(",", ":"), ensure_ascii=False)
         # 生成md5
         content_md5 = doContentMd5(body)
     # 拼接待签名字符串

+ 6 - 2
common/esigntool/esign_config.py

@@ -1,5 +1,7 @@
+from esign_algorithm import buildHeader
+
 # 公共参数配置类
-class config:
+class Config:
     def __init__(self):
         """
         项目配置类,在此配置公共参数
@@ -7,5 +9,7 @@ class config:
         # 沙箱appid获取路径:https://open.esign.cn/doc/opendoc/saas_api/vwtg6m
         # 沙箱appid获取路径:https://open.esign.cn/doc/opendoc/saas_api/zag8bm
         self.appId = "7439100277"  # 项目appid
-        self.scert = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzRMTBAikgkfEVhcbhqaWSm4jfFB2aUHHeW9MvshM6wTdAGOWTwSdK0odMXo+t5C18tCrOkaYc9xjl3Zm4rRfDy9aT+8OPwr+roWbiP4k+E/k2I7+qlzG7XwVA6hw4ioUxY0sdxqIGz/qIgGtPIgEgiGENAgH5oKangoriqr/sj+qPet96q32taoCdbGj6yav/W8FDHw9t+fn/0OrPL4AiQgzDdlb43IhTg4RP0Gz02Og///Ck1j2GOaH2iIwIDAQAB"  # 项目密钥
+        self.scert = "fda5f9e9652571066631f7ba938092e1"  # 项目密钥
         self.host = "https://smlopenapi.esign.cn"  # 沙箱请求地址,正式环境地址:https://openapi.esign.cn
+        self.ordid = 'f25ca92b44a34b2c94289e0afec2518b'
+        self.templates_id = "266369d0efd94e14a78035b881e8cb93"

+ 14 - 0
common/esigntool/esign_templates.py

@@ -0,0 +1,14 @@
+import requests
+from esign_config import Config
+
+config = Config()
+
+url = config.host+f'/v3/sign-templates?orgId={config.ordid}'
+
+print(url)
+def get_templates():
+    """获取公司在e签宝下所有的模板"""
+    res = requests.get(url, headers=config.headers)
+    return res.json()
+
+print(get_templates())

+ 0 - 18
common/esigntool/esign_tool_info.py

@@ -1,18 +0,0 @@
-# coding=utf-8
-sdk_version = "esigntool1.0.1"
-supported_version = "py3.0 MORE THAN"
-info = "esigntool核心工具包,主要处理e签宝公有云产品接口调用时的签名计算," \
-       "通过esigntool.build_sign_json_header构造签名鉴权+json数据格式的请求头," \
-       "让开发者无需关注具体的请求签名算法,专注于接口业务的json参数构造"
-
-
-def get_esign_sdk_info():
-    return info
-
-
-def get_esign_sdk_verion():
-    return sdk_version
-
-
-def get_esign_sdk_supported_version():
-    return supported_version

+ 68 - 0
common/esigntool/main.py

@@ -0,0 +1,68 @@
+import requests
+import json
+from common.esigntool.esign_config import Config
+from common.esigntool.esign_algorithm import buildSignJsonHeader
+import time
+from datetime import datetime
+config = Config()
+
+def get_auth_flow_id():
+    """获取机构认证&授权页面链接"""
+    api_path = "/v3/org-auth-url"
+    method = "POST"
+    body = {
+        "clientType": "ALL",
+        "redirectConfig": {
+            "redirectUrl": "https://www.baidu.com"
+        },
+        "orgAuthConfig": {
+            "orgId": config.ordid,
+        }
+    }
+    # 签名使用原始字典,内部会统一 json.dumps(去空格),再用完全一致的字符串发送
+    json_headers = buildSignJsonHeader(config.appId, config.scert, method, api_path, body=body)
+    body_json = json.dumps(body, separators=(",", ":"), ensure_ascii=False)
+    resp = requests.request(method, config.host + api_path, data=body_json, headers=json_headers)
+    print(resp.text)
+    return resp.text
+
+# get_auth_flow_id()
+
+
+def get_template_detail():
+    """查询合同模板中控件详情"""
+    api_path = f"/v3/doc-templates/{config.templates_id}"
+    method = "GET"
+    json_headers = buildSignJsonHeader(config.appId, config.scert, method, api_path)
+    resp = requests.request(method, config.host + api_path, headers=json_headers)
+    print(resp.text)
+
+
+def fill_in_template():
+    """填写模板生成文件"""
+    api_path = "/v3/files/create-by-doc-template"
+    method = "POST"
+    body = {
+        "docTemplateId": config.templates_id,
+        "fileName": "U店在这-商户入驻协议",
+        "components": [
+            {
+                "componentKey": "alien_name",
+                "componentValue": "爱丽恩严(大连)商务科技有限公司"
+            },
+            {
+                "componentKey": "store_name",
+                "componentValue": "潘子"
+            },
+            {
+                "componentKey": "date",
+                "componentValue": datetime.now().strftime("%Y年%m月%d日")
+            }
+        ]
+    }
+    json_headers = buildSignJsonHeader(config.appId, config.scert, method, api_path, body=body)
+    body_json = json.dumps(body, separators=(",", ":"), ensure_ascii=False)
+    resp = requests.request(method, config.host + api_path, data=body_json, headers=json_headers)
+    print(resp.text)
+    return resp.text
+

+ 1 - 1
common/run/moduledemo/auth/auth_launch.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # 认证和授权服务API - 实名认证 - 发起类
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/auth/auth_query.py

@@ -6,7 +6,7 @@ from esigntool import esign_run_print_outer
 
 # 认证和授权服务API - 实名认证 - 查询类
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 # 查询个人认证信息

+ 1 - 1
common/run/moduledemo/fileandtemplate/expand.py

@@ -6,7 +6,7 @@ from esigntool import esign_run_print_outer
 
 # 拓展功能API
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/fileandtemplate/file.py

@@ -7,7 +7,7 @@ from esigntool.esign_file import fileHelp
 
 # 文件类API
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/fileandtemplate/template.py

@@ -7,7 +7,7 @@ from esigntool import esign_run_print_outer
 # 合同模板类API
 
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/members/org_member.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # 企业机构成员服务API
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/order/order_buy.py

@@ -6,7 +6,7 @@ from esigntool import esign_run_print_outer
 
 # 套餐服务API - 套餐购买 - 购买类
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 # 获取购买e签宝套餐链接

+ 1 - 1
common/run/moduledemo/order/order_query.py

@@ -6,7 +6,7 @@ from esigntool import esign_run_print_outer
 
 # 套餐服务API - 套餐购买 - 查询类
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 # 查询e签宝套餐余量

+ 1 - 1
common/run/moduledemo/seal/org_seals.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # 印章服务API
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/seal/psn_seals.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # 印章服务API
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/seal/upload_url.py

@@ -8,7 +8,7 @@ from esigntool import esign_run_print_outer, fileHelp
 
 # 印章服务API
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/sign/attachments_change.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # 合同文件签署服务API - 待签文件及附属材料 - 变更类
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/sign/copiers_change.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # 合同文件签署服务API - 抄送方 - 变更类
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/sign/signfields_change.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # 合同文件签署服务API - 签署区 - 变更类
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/sign/signflow_change.py

@@ -6,7 +6,7 @@ from esigntool import esign_run_print_outer
 # 合同文件签署服务API - 签署流程 - 变更类
 
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/sign/signflow_download.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # 合同文件签署服务API - 签署流程 - 下载类
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/sign/signflow_launch.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # 合同文件签署服务API - 签署流程 - 发起类
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/sign/signflow_query.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # 合同文件签署服务API - 签署流程 - 查询类
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/moduledemo/sign/signflow_rescission.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # 合同文件签署服务API - 合同解约服务
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/scenedome/b2b_autosign_demo.py

@@ -12,7 +12,7 @@ from esigntool.esign_file import fileHelp
  * 2、发起签署时,设置signFields入参规则:signers.orgSignerInfo对象中的orgId为平台方企业账号id,assignedSealId为授权企业的印章id,autoSign设置为true
  * 3、流程完结后,下载签署后文件
  """
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/scenedome/b2b_handsign_demo.py

@@ -8,7 +8,7 @@ from esigntool.esign_file import fileHelp
 # 平台方(签署方1):appId所属企业为平台方,默认平台方已完成实名认证,通过获取企业签署帐号来实现平台方自动签署。
 # 企业用户手动签署(签署方2):通过传入企业名称和经办人信息,来实现企业用户手动签署。
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/scenedome/b2c_handsign_demo.py

@@ -8,7 +8,7 @@ from esigntool.esign_file import fileHelp
 # 平台方(签署方1):appId所属企业为平台方,默认平台方已完成实名认证,通过获取企业签署帐号来实现平台方自动签署。
 # 个人用户手动签署(签署方2):通过传入个人信息,来实现个人用户手动签署。
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/scenedome/dynamic_table_demo.py

@@ -7,7 +7,7 @@ import time
 
 # 模版场景:支持动态表格,上传的文件必须是.doc 或 .docx 格式
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/scenedome/order_demo.py

@@ -5,7 +5,7 @@ from esigntool import esign_run_print_outer
 
 # EP订单场景:需要联系交付顾问协助配置商品信息,沙箱环境获取到商品购买链接后,可以购买测试套餐进行业务测试
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer

+ 1 - 1
common/run/scenedome/signature_check_demo.py

@@ -6,7 +6,7 @@ from esigntool import esign_run_print_outer
 
 # 回调通知验证签名方法:通过对返回参数计算签名,并和回调中的签名对比,如一致则验证成功
 
-config = esigntool.config()  # 初始化配置类
+config = esigntool.Config()  # 初始化配置类
 
 
 @esign_run_print_outer