| 1234567891011121314151617181920212223242526272829303132 |
- from fastapi import APIRouter
- from fastapi.params import Depends
- from alien_store.api.deps import get_contract_service
- from alien_store.schemas.request.contract_store import TemplatesCreate
- from alien_store.services.contract_server import ContractServer
- from common.esigntool.main import fill_in_template
- import json
- router = APIRouter()
- @router.get("/")
- async def index():
- return {"module": "Contract", "status": "Ok"}
- @router.post("/get_esign_templates")
- async def create_esign_templates(templates_data: TemplatesCreate, templates_server: ContractServer = Depends(get_contract_service)):
- # 调用 e签宝生成文件
- res_text = fill_in_template(templates_data.merchant_name)
- try:
- res_data = json.loads(res_text)
- except json.JSONDecodeError:
- return {"success": False, "message": "e签宝返回非 JSON", "raw": res_text}
- # 从返回结构提取下载链接,需与实际返回字段匹配
- try:
- contract_url = res_data["data"]["fileDownloadUrl"]
- except Exception:
- return {"success": False, "message": "e签宝返回缺少 fileDownloadUrl", "raw": res_data}
- # pydantic v2 使用 model_copy 更新字段
- data_with_url = templates_data.model_copy(update={"contract_url": contract_url, "seal_url": None})
- return await templates_server.create_template(data_with_url)
|