config.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from pydantic_settings import BaseSettings
  2. class Settings(BaseSettings):
  3. """从 .env 文件读取配置项"""
  4. # 数据库连接参数
  5. db_host: str = "localhost"
  6. db_port: int = 5432
  7. db_user: str = "postgres"
  8. db_password: str = "postgres"
  9. db_name: str = "domain_monitor"
  10. # 服务配置
  11. host: str = "0.0.0.0"
  12. port: int = 8000
  13. debug: bool = True
  14. # 外部 API 配置(格式待定)
  15. domain_api_base_url: str = ""
  16. domain_api_key: str = ""
  17. # 阿里云短信配置
  18. sms_access_key_id: str = ""
  19. sms_access_key_secret: str = ""
  20. sms_sign_name: str = "四川网讯创智数字产业发展"
  21. # 短信模板 CODE
  22. sms_template_code_verify: str = "SMS_333915522"
  23. sms_template_code_expired: str = "SMS_506350367"
  24. sms_template_code_restored: str = "SMS_506275397"
  25. sms_template_code_warning: str = "SMS_506330424"
  26. # 超管余额预警短信模板
  27. sms_template_code_sa_balance_warning: str = "" # 余额预警 {companyName, remainAmount}
  28. sms_template_code_sa_balance_depleted: str = "" # 余额耗尽 {companyName}
  29. sa_balance_warning_threshold: float = 100.0 # 全局预警阈值(元)
  30. # Redis
  31. redis_host: str = "localhost"
  32. redis_port: int = 6379
  33. redis_password: str = ""
  34. redis_db: int = 0
  35. @property
  36. def database_url(self) -> str:
  37. """拼接 SQLAlchemy 异步连接字符串"""
  38. return f"postgresql+asyncpg://{self.db_user}:{self.db_password}@{self.db_host}:{self.db_port}/{self.db_name}"
  39. model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}
  40. settings = Settings()