yj
2025-07-23 1225b6cbf0a028b765a0ab6d784bcb80459a67bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
配置管理模块
"""
 
import os
import json
 
 
class Settings:
    """应用配置"""
 
    def __init__(self, config_file: str = "config.json"):
        """初始化配置,从JSON文件加载"""
        self.config_file = config_file
        self._load_config()
 
    def _load_config(self):
        """从JSON文件加载配置"""
        try:
            if os.path.exists(self.config_file):
                with open(self.config_file, 'r', encoding='utf-8') as f:
                    config_data = json.load(f)
                self._set_config_from_dict(config_data)
            else:
                # 如果配置文件不存在,使用默认值
                self._set_default_config()
        except Exception as e:
            print(f"加载配置文件失败: {e}")
            self._set_default_config()
 
    def _set_config_from_dict(self, config_data: dict):
        """从字典设置配置"""
        # 数据库配置
        self.database_url = config_data.get("database", {}).get("url", "mysql+pymysql://root:TAI%402019%23Zjun@120.24.39.179:3306/ecloud_dify")
 
        # Redis配置
        self.redis_url = config_data.get("redis", {}).get("url", "redis://localhost:6379/0")
 
        # E云管家配置
        ecloud_config = config_data.get("ecloud", {})
        self.ecloud_base_url = ecloud_config.get("base_url", "http://125.122.152.142:9899")
        self.ecloud_authorization = ecloud_config.get("authorization", "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzYxMTQ1MjE3NSIsInBhc3N3b3JkIjoiJDJhJDEwJEU3Ry5LOEJzekphM2JGQlh0SG8vOXVrUk1NalVweGVVemguUDRnMkJBdHN2YXpBb0JIQWJpIn0.Gd2vbeJjL5pUGFhUngWPLkDTLhD3GUaEPXOkdoTf4KRh9o2FtST1OZJxmZuGdUy7WIYlIPVueoVyIu5iHOyi8A")
        self.ecloud_w_id = ecloud_config.get("w_id", "")
 
        # DifyAI配置
        dify_config = config_data.get("dify", {})
        self.dify_base_url = dify_config.get("base_url", "https://api.dify.ai/v1")
        self.dify_api_key = dify_config.get("api_key", "app-OMnBr7zsf5UTV83Ey8QcSErA")
 
        # 服务配置
        server_config = config_data.get("server", {})
        self.server_host = server_config.get("host", "0.0.0.0")
        self.server_port = server_config.get("port", 7979)
        self.debug = server_config.get("debug", True)
 
        # 日志配置
        logging_config = config_data.get("logging", {})
        self.log_level = logging_config.get("level", "INFO")
        self.log_file = logging_config.get("file", "logs/app.log")
 
        # 消息处理配置
        msg_config = config_data.get("message_processing", {})
        self.max_retry_count = msg_config.get("max_retry_count", 3)
        self.retry_delay = msg_config.get("retry_delay", 5)
        self.queue_timeout = msg_config.get("queue_timeout", 300)
 
        # 客服配置
        customer_service_config = config_data.get("customer_service", {})
        self.customer_service_names = customer_service_config.get("names", ["客服1", "客服2"])
 
    def _set_default_config(self):
        """设置默认配置"""
        # 数据库配置
        self.database_url = "mysql+pymysql://root:TAI%402019%23Zjun@120.24.39.179:3306/ecloud_dify"
 
        # Redis配置
        self.redis_url = "redis://localhost:6379/0"
 
        # E云管家配置
        self.ecloud_base_url = "http://125.122.152.142:9899"
        self.ecloud_authorization = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzYxMTQ1MjE3NSIsInBhc3N3b3JkIjoiJDJhJDEwJEU3Ry5LOEJzekphM2JGQlh0SG8vOXVrUk1NalVweGVVemguUDRnMkJBdHN2YXpBb0JIQWJpIn0.Gd2vbeJjL5pUGFhUngWPLkDTLhD3GUaEPXOkdoTf4KRh9o2FtST1OZJxmZuGdUy7WIYlIPVueoVyIu5iHOyi8A"
        self.ecloud_w_id = ""
 
        # DifyAI配置
        self.dify_base_url = "https://api.dify.ai/v1"
        self.dify_api_key = "app-OMnBr7zsf5UTV83Ey8QcSErA"
 
        # 服务配置
        self.server_host = "0.0.0.0"
        self.server_port = 7979
        self.debug = True
 
        # 日志配置
        self.log_level = "INFO"
        self.log_file = "logs/app.log"
 
        # 消息处理配置
        self.max_retry_count = 3
        self.retry_delay = 5
        self.queue_timeout = 300
 
        # 客服配置
        self.customer_service_names = ["客服1", "客服2"]
 
 
# 全局配置实例
settings = Settings()