|
@@ -1,26 +1,55 @@
|
|
|
-
|
|
|
|
|
import os
|
|
import os
|
|
|
|
|
+from pathlib import Path
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+APP_ENV = os.getenv("APP_ENV", "dev")
|
|
|
|
|
+ROOT_DIR = Path(__file__).resolve().parents[3]
|
|
|
|
|
+ENV_FILE = ROOT_DIR / f".env.{APP_ENV}"
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _load_env_file(path: Path) -> None:
|
|
|
|
|
+ if not path.exists():
|
|
|
|
|
+ return
|
|
|
|
|
+ for raw_line in path.read_text(encoding="utf-8").splitlines():
|
|
|
|
|
+ line = raw_line.strip()
|
|
|
|
|
+ if not line or line.startswith("#") or "=" not in line:
|
|
|
|
|
+ continue
|
|
|
|
|
+ key, value = line.split("=", 1)
|
|
|
|
|
+ key = key.strip()
|
|
|
|
|
+ if not key or key in os.environ:
|
|
|
|
|
+ continue
|
|
|
|
|
+ os.environ[key] = value.strip().strip("\"'")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+_load_env_file(ENV_FILE)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _required_env(name: str) -> str:
|
|
|
|
|
+ value = os.getenv(name)
|
|
|
|
|
+ if not value:
|
|
|
|
|
+ raise RuntimeError(f"缺少 e签宝环境变量: {name}")
|
|
|
|
|
+ return value
|
|
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
class Config:
|
|
|
def __init__(self):
|
|
def __init__(self):
|
|
|
- self.appId = "7439100277"
|
|
|
|
|
- self.scert = "fda5f9e9652571066631f7ba938092e1"
|
|
|
|
|
- self.host = "https://smlopenapi.esign.cn"
|
|
|
|
|
- self.ordid = "f25ca92b44a34b2c94289e0afec2518b"
|
|
|
|
|
- self.templates_id = "266369d0efd94e14a78035b881e8cb93"
|
|
|
|
|
|
|
+ self.appId = _required_env("ESIGN_APP_ID")
|
|
|
|
|
+ self.scert = _required_env("ESIGN_APP_SECRET")
|
|
|
|
|
+ self.host = _required_env("ESIGN_HOST").rstrip("/")
|
|
|
|
|
+ self.ordid = _required_env("ESIGN_ORG_ID")
|
|
|
self.templates_map = {
|
|
self.templates_map = {
|
|
|
- "store_agreement": "266369d0efd94e14a78035b881e8cb93",
|
|
|
|
|
- "lawyer_agreement": "28f8c0337b044ca0acb6e3559f526d95",
|
|
|
|
|
- "alipay_auth": "f42e72f59bb648c280ec4c3e937e0c26",
|
|
|
|
|
- "wechat_pay_commitment": "18ecbd5a85cc4a0ba190a010a79bf8da",
|
|
|
|
|
|
|
+ "store_agreement": _required_env("ESIGN_TEMPLATE_STORE_AGREEMENT"),
|
|
|
|
|
+ "lawyer_agreement": _required_env("ESIGN_TEMPLATE_LAWYER_AGREEMENT"),
|
|
|
|
|
+ "alipay_auth": _required_env("ESIGN_TEMPLATE_ALIPAY_AUTH"),
|
|
|
|
|
+ "wechat_pay_commitment": _required_env("ESIGN_TEMPLATE_WECHAT_PAY_COMMITMENT"),
|
|
|
}
|
|
}
|
|
|
|
|
+ self.templates_id = self.templates_map["store_agreement"]
|
|
|
self.template_file_names = {
|
|
self.template_file_names = {
|
|
|
- "store_agreement": "U店在这-商户入驻协议",
|
|
|
|
|
- "lawyer_agreement": "U店在这-律所入驻协议",
|
|
|
|
|
- "alipay_auth": "U店在这-支付宝授权函",
|
|
|
|
|
- "wechat_pay_commitment": "U店在这-微信支付承诺函",
|
|
|
|
|
|
|
+ "store_agreement": _required_env("ESIGN_TEMPLATE_FILE_STORE_AGREEMENT"),
|
|
|
|
|
+ "lawyer_agreement": _required_env("ESIGN_TEMPLATE_FILE_LAWYER_AGREEMENT"),
|
|
|
|
|
+ "alipay_auth": _required_env("ESIGN_TEMPLATE_FILE_ALIPAY_AUTH"),
|
|
|
|
|
+ "wechat_pay_commitment": _required_env("ESIGN_TEMPLATE_FILE_WECHAT_PAY_COMMITMENT"),
|
|
|
}
|
|
}
|
|
|
- self.callback_url = os.getenv("ESIGN_CALLBACK_URL", "http://120.26.186.130:33333/api/contract/esign/callback")
|
|
|
|
|
|
|
+ self.callback_url = _required_env("ESIGN_CALLBACK_URL")
|
|
|
self.developer_callback_url = os.getenv("ESIGN_DEVELOPER_CALLBACK_URL", self.callback_url)
|
|
self.developer_callback_url = os.getenv("ESIGN_DEVELOPER_CALLBACK_URL", self.callback_url)
|
|
|
self.redirect_url = os.getenv("ESIGN_REDIRECT_URL", "https://www.esign.cn/")
|
|
self.redirect_url = os.getenv("ESIGN_REDIRECT_URL", "https://www.esign.cn/")
|