cc9d9f03f7
- 新增 app/core/meituan.py: 美团联盟 API 客户端 (S-Ca 签名, query_coupon, get_referral_link) - 新增 app/api/v1/meituan.py: /api/v1/meituan/coupons 和 /feed 路由, 支持按经纬度推荐 - 新增 app/schemas/meituan.py: 请求/响应 Pydantic Schema - app/main.py: 注册 meituan_router - app/core/config.py: 新增 MT_CPS_* 配置项, .env 路径改为绝对路径避免 CWD 问题 - .env.example: 补充美团联盟 CPS 配置模板 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
79 lines
2.1 KiB
Python
79 lines
2.1 KiB
Python
"""全局配置。
|
|
|
|
用 pydantic-settings 从环境变量 + .env 文件加载。所有可调参数集中在这里,
|
|
业务代码通过 `from app.core.config import settings` 引用,不再读 os.environ。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from functools import lru_cache
|
|
from pathlib import Path
|
|
from typing import Literal
|
|
|
|
from pydantic import Field
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
_PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(
|
|
env_file=str(_PROJECT_ROOT / ".env"),
|
|
env_file_encoding="utf-8",
|
|
case_sensitive=False,
|
|
extra="ignore",
|
|
)
|
|
|
|
# ===== 环境 =====
|
|
APP_ENV: Literal["dev", "prod"] = "dev"
|
|
APP_NAME: str = "shaguabijia-app-server"
|
|
APP_DEBUG: bool = True
|
|
|
|
# ===== 数据库 =====
|
|
DATABASE_URL: str = "sqlite:///./data/app.db"
|
|
|
|
# ===== JWT =====
|
|
JWT_SECRET_KEY: str = "change-me"
|
|
JWT_ALGORITHM: str = "HS256"
|
|
JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 120
|
|
JWT_REFRESH_TOKEN_EXPIRE_DAYS: int = 30
|
|
|
|
# ===== 极光 =====
|
|
JG_APP_KEY: str = ""
|
|
JG_MASTER_SECRET: str = ""
|
|
JG_PRIVATE_KEY_PATH: str = "./secrets/jverify_rsa_private.pem"
|
|
JG_VERIFY_ENDPOINT: str = "https://api.verification.jpush.cn/v1/web/loginTokenVerify"
|
|
JG_REQUEST_TIMEOUT_SEC: int = 15
|
|
|
|
# ===== 短信 =====
|
|
SMS_MOCK: bool = True
|
|
SMS_CODE_TTL_SEC: int = 300
|
|
SMS_SEND_INTERVAL_SEC: int = 60
|
|
|
|
# ===== 美团联盟 CPS =====
|
|
MT_CPS_APP_KEY: str = ""
|
|
MT_CPS_APP_SECRET: str = ""
|
|
MT_CPS_HOST: str = "https://media.meituan.com"
|
|
MT_CPS_TIMEOUT_SEC: int = 15
|
|
MT_CPS_DEFAULT_SID: str = "sgbjia"
|
|
|
|
# ===== CORS =====
|
|
CORS_ALLOW_ORIGINS: str = ""
|
|
|
|
@property
|
|
def cors_origins_list(self) -> list[str]:
|
|
if not self.CORS_ALLOW_ORIGINS.strip():
|
|
return []
|
|
return [o.strip() for o in self.CORS_ALLOW_ORIGINS.split(",") if o.strip()]
|
|
|
|
@property
|
|
def is_prod(self) -> bool:
|
|
return self.APP_ENV == "prod"
|
|
|
|
|
|
@lru_cache(maxsize=1)
|
|
def get_settings() -> Settings:
|
|
return Settings()
|
|
|
|
|
|
settings = get_settings()
|