浏览代码

生产环境下,apikey与设备码绑定, 防止盗用.
更新依赖.

longjoedyy 1 月之前
父节点
当前提交
e1431e6546
共有 3 个文件被更改,包括 35 次插入12 次删除
  1. 26 11
      README.md
  2. 9 1
      config/settings.py
  3. 二进制
      requirements.txt

+ 26 - 11
README.md

@@ -78,30 +78,45 @@ LongjoeAgent/
 - 安装依赖包
 
 ### 安装步骤
-0. 安装python 3.8+
-```https://www.python.org/downloads/```
-
-1. 克隆项目
-
-
-2. 安装依赖
+1. 安装python 3.13.7
+```https://www.python.org/ftp/python/3.13.7/python-3.13.7-amd64.exe```
+
+2. 克隆项目
+
+3. 创建并激活虚拟环境
+   #### 进入项目目录
+   ```bash
+   cd your_project_folder
+   ```
+   
+   #### 创建名为 venv 的虚拟环境
+   ```bash
+   python -m venv venv
+   ```
+   
+   #### 激活环境
+   ```bash
+   venv\Scripts\activate
+   ```
+
+4. 在虚拟环境中安装依赖
 ```bash
 pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
 ```
 
-3. 配置DEEPSEEK_API_KEY
+5. 配置DEEPSEEK_API_KEY
 参考`.env.development.example`创建 `.env.development` 文件并配置DEEPSEEK_API_KEY
 
 
-4. 启动服务
+6. 启动服务
 ```bash
 python app.py
 ```
 
-5. 服务启动后访问
+7. 服务启动后访问
 健康检查: http://localhost:8888/health, 复制"device_id"的值,向耀申请注册码
 
-6. 配置注册码
+8. 配置注册码
 参考`.registration.example`创建 `.registration` 文件并配置REGISTRATION_CODE
 
 ## API接口

+ 9 - 1
config/settings.py

@@ -1,5 +1,7 @@
 import os
+import json
 from pathlib import Path
+from utils.device_id import get_device_id
 
 
 # 基础配置
@@ -83,7 +85,13 @@ class Settings:
             ct = base64.b64decode(encrypted_key)
             pt = unpad(cipher.decrypt(ct), AES.block_size)
 
-            return pt.decode("utf-8")
+            data = json.loads(pt.decode("utf-8"))
+
+            # 验证设备ID
+            if data.get("device_code", "") != get_device_id():
+                raise ValueError("设备ID不匹配,APIKEY无效,请联系软件公司")
+
+            return data.get("api_key", "")
         except Exception as e:
             raise ValueError(f"解密失败: {e}")
 

二进制
requirements.txt