mengqiankang 2 месяцев назад
Родитель
Сommit
a72fc94611
2 измененных файлов с 25 добавлено и 8 удалено
  1. 15 2
      alien_store/api/router.py
  2. 10 6
      common/esigntool/main.py

+ 15 - 2
alien_store/api/router.py

@@ -63,8 +63,21 @@ async def create_esign_templates(templates_data: TemplatesCreate, templates_serv
         return {"success": False, "message": "e签宝返回缺少 fileDownloadUrl", "raw": res_data}
 
     sign_data = create_by_file(file_id, file_name, templates_data.contact_phone, templates_data.merchant_name)
-    sign_json = json.loads(sign_data)
-    sing_id = sign_json["data"]["signFlowId"]
+    try:
+        sign_json = json.loads(sign_data)
+    except json.JSONDecodeError:
+        logger.error(f"create_by_file non-json resp: {sign_data}")
+        return {"success": False, "message": "e签宝 create_by_file 返回非 JSON", "raw": sign_data}
+
+    if not sign_json.get("data"):
+        logger.error(f"create_by_file failed or missing data: {sign_json}")
+        return {"success": False, "message": "e签宝创建签署流程失败", "raw": sign_json}
+
+    sing_id = sign_json["data"].get("signFlowId")
+    if not sing_id:
+        logger.error(f"create_by_file missing signFlowId: {sign_json}")
+        return {"success": False, "message": "e签宝返回缺少 signFlowId", "raw": sign_json}
+
     result_contract = {
         "contract_url": contract_url,
         "file_name": file_name,

+ 10 - 6
common/esigntool/main.py

@@ -6,7 +6,7 @@ import time
 from datetime import datetime
 config = Config()
 
-def get_auth_flow_id():
+def get_auth_flow_id(org_name, org_id, legal_rep_name, legal_rep_id):
     """获取机构认证&授权页面链接"""
     api_path = "/v3/org-auth-url"
     method = "POST"
@@ -16,12 +16,16 @@ def get_auth_flow_id():
             "redirectUrl": "https://www.baidu.com"
         },
         "orgAuthConfig": {
-            "orgName": "爱丽恩严(大连)商务科技有限公司深圳分公司",
+            # "orgName": "爱丽恩严(大连)商务科技有限公司深圳分公司",
+            "orgName": org_name,
             "orgInfo": {
-                "orgIDCardNum": "91440300MADDW7XC4C",
+                # "orgIDCardNum": "91440300MADDW7XC4C",
+                "orgIDCardNum": org_id,
                 "orgIDCardType": "CRED_ORG_USCC",
-                "legalRepName": "彭少荣",
-                "legalRepIDCardNum": "362204198807182420",
+                # "legalRepName": "彭少荣",
+                "legalRepName": legal_rep_name,
+                # "legalRepIDCardNum": "362204198807182420",
+                "legalRepIDCardNum": legal_rep_id,
                 "legalRepIDCardType": "CRED_PSN_CH_IDCARD"
             },
             "transactorInfo": {
@@ -51,7 +55,7 @@ def get_auth_flow_id():
     print(resp.text)
     return resp.text
 
-get_auth_flow_id()
+# get_auth_flow_id()
 
 def get_template_detail():
     """查询合同模板中控件详情"""