| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- from pydantic_settings import BaseSettings
- class Settings(BaseSettings):
- """从 .env 文件读取配置项"""
- # 数据库连接参数
- db_host: str = "localhost"
- db_port: int = 5432
- db_user: str = "postgres"
- db_password: str = "postgres"
- db_name: str = "domain_monitor"
- # 服务配置
- host: str = "0.0.0.0"
- port: int = 8000
- debug: bool = True
- # 外部 API 配置(格式待定)
- domain_api_base_url: str = ""
- domain_api_key: str = ""
- # 阿里云短信配置
- sms_access_key_id: str = ""
- sms_access_key_secret: str = ""
- sms_sign_name: str = "四川网讯创智数字产业发展"
- # 短信模板 CODE
- sms_template_code_verify: str = "SMS_333915522"
- sms_template_code_expired: str = "SMS_506350367"
- sms_template_code_restored: str = "SMS_506275397"
- sms_template_code_warning: str = "SMS_506330424"
- # 超管余额预警短信模板
- sms_template_code_sa_balance_warning: str = "" # 余额预警 {companyName, remainAmount}
- sms_template_code_sa_balance_depleted: str = "" # 余额耗尽 {companyName}
- sa_balance_warning_threshold: float = 100.0 # 全局预警阈值(元)
- # Redis
- redis_host: str = "localhost"
- redis_port: int = 6379
- redis_password: str = ""
- redis_db: int = 0
- @property
- def database_url(self) -> str:
- """拼接 SQLAlchemy 异步连接字符串"""
- return f"postgresql+asyncpg://{self.db_user}:{self.db_password}@{self.db_host}:{self.db_port}/{self.db_name}"
- model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}
- settings = Settings()
|