# aiserver **Repository Path**: bx-ai/aiserver ## Basic Information - **Project Name**: aiserver - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-28 - **Last Updated**: 2025-09-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AI Java Server 基于Spring Boot的安全REST API服务器,支持多种登录方式和数据加密。 ## 功能特性 ### 🔐 安全特性 - **数据加密**: 支持AES对称加密,保护敏感数据传输 - **JWT认证**: 基于JWT的无状态身份认证 - **限流保护**: 基于IP的请求频率限制 - **登录保护**: 防暴力破解,支持账户锁定机制 ### 🚀 登录方式 - **用户名密码登录**: 传统的用户名密码认证 - **手机验证码登录**: 支持短信验证码登录 - **微信登录**: 支持微信公众号授权登录 ### 🛠 技术栈 - **框架**: Spring Boot 2.7.18 - **数据库**: MySQL 8.0 + MyBatis - **缓存**: Redis - **安全**: Spring Security + JWT - **工具**: Hutool、FastJSON ## 快速开始 ### 环境要求 - JDK 1.8+ - MySQL 8.0+ - Redis 6.0+ - Maven 3.6+ ### 1. 克隆项目 ```bash git clone cd ai-java-server ``` ### 2. 配置数据库 ```bash # 创建数据库 mysql -u root -p < src/main/resources/sql/init.sql ``` ### 3. 修改配置 编辑 `src/main/resources/application.yml`: ```yaml spring: datasource: url: jdbc:mysql://localhost:3306/ai_server username: your_username password: your_password redis: host: localhost port: 6379 password: your_redis_password ``` ### 4. 启动项目 ```bash mvn spring-boot:run ``` 服务器将在 `http://localhost:8080/api` 启动。 ## API 文档 ### 认证接口 #### 1. 用户名密码登录 ```http POST /api/auth/login Content-Type: application/json { "username": "admin", "password": "123456", "captcha": "1234", "captchaKey": "captcha_key" } ``` #### 2. 手机验证码登录 ```http POST /api/auth/sms-login Content-Type: application/x-www-form-urlencoded phone=13800138000&code=123456 ``` #### 3. 微信登录 ```http POST /api/auth/wechat-login Content-Type: application/x-www-form-urlencoded code=wechat_auth_code&state=optional_state ``` #### 4. 发送短信验证码 ```http POST /api/auth/send-sms-code Content-Type: application/x-www-form-urlencoded phone=13800138000 ``` #### 5. 生成图片验证码 ```http GET /api/auth/captcha ``` #### 6. 刷新Token ```http POST /api/auth/refresh-token Content-Type: application/x-www-form-urlencoded refreshToken=your_refresh_token ``` #### 7. 登出 ```http POST /api/auth/logout Authorization: Bearer your_access_token ``` ### 用户接口 #### 1. 获取用户信息 ```http GET /api/user/profile Authorization: Bearer your_access_token ``` #### 2. 更新用户信息 ```http PUT /api/user/profile Authorization: Bearer your_access_token Content-Type: application/x-www-form-urlencoded nickname=新昵称&email=new@example.com ``` #### 3. 修改密码 ```http POST /api/user/change-password Authorization: Bearer your_access_token Content-Type: application/x-www-form-urlencoded oldPassword=123456&newPassword=654321 ``` ## 数据加密 ### 请求加密 对于需要加密的请求,设置请求头: ```http X-Encrypted: true Content-Type: application/json { "data": "encrypted_data_here" } ``` ### 响应加密 服务器会根据请求头自动决定是否加密响应数据。 ## 安全配置 ### 限流配置 - 默认每分钟100次请求 - 可在 `application.yml` 中修改 `app.security.rate-limit` ### 登录保护 - 默认5次失败后锁定账户 - 锁定时间30分钟 - 可在配置文件中调整 ### JWT配置 - 访问token有效期:24小时 - 刷新token有效期:7天 - 支持token黑名单机制 ## 微信登录配置 1. 在微信公众平台配置回调域名 2. 修改 `application.yml` 中的微信配置: ```yaml app: wechat: app-id: your_wechat_app_id app-secret: your_wechat_app_secret redirect-uri: http://your-domain.com/api/auth/wechat/callback ``` ## 测试账户 系统初始化时会创建以下测试账户: - 用户名: `admin`, 密码: `123456` - 用户名: `test`, 密码: `123456` ## 开发指南 ### 添加新的API接口 1. 在对应的Controller中添加方法 2. 使用 `@RequestMapping` 注解定义路径 3. 返回 `Result` 类型的统一响应 ### 自定义拦截器 1. 实现 `HandlerInterceptor` 接口 2. 在 `WebConfig` 中注册拦截器 ### 数据库操作 1. 在 `entity` 包中定义实体类 2. 在 `mapper` 包中定义Mapper接口 3. 使用MyBatis注解或XML配置SQL ## 部署说明 ### Docker部署 ```dockerfile FROM openjdk:8-jre-alpine COPY target/ai-java-server-1.0.0.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "/app.jar"] ``` ### 生产环境配置 1. 修改数据库连接配置 2. 配置Redis集群 3. 设置日志级别为INFO 4. 配置HTTPS证书 ## 常见问题 ### Q: 如何修改JWT密钥? A: 修改 `application.yml` 中的 `app.jwt.secret` 配置。 ### Q: 如何集成短信服务? A: 在 `AuthServiceImpl.sendSmsCode` 方法中集成第三方短信服务。 ### Q: 如何添加新的登录方式? A: 在 `AuthService` 中添加新方法,在 `AuthController` 中添加对应接口。 ## 许可证 MIT License ## 联系方式 如有问题,请提交Issue或联系开发团队。