基于 Spring Boot + DeepSeek API 的智能塔罗牌占卜系统,支持灵活接入多种 AI 服务。
- 🃏 完整 78 张塔罗牌:22 张大阿卡那 + 56 张小阿卡那,正逆位随机
- 🎲 不重复抽牌算法:采用删除法保证同一占卜内牌不重复
- 🤖 AI 智能解读:支持 DeepSeek、OpenAI 等多种 AI 服务,可灵活切换
- 📱 响应式设计:完美支持 PC 和手机端访问
- 🖼️ 智能图片加载:卡背占位 + 懒加载,加载失败自动降级为文字卡片
- 🔧 可插拔 AI:只需修改配置即可切换不同的 AI 服务
| 技术 | 说明 |
|---|---|
| Java 11 | 后端语言 |
| Spring Boot 2.7.0 | 后端框架 |
| Maven | 项目管理 |
| HTML5/CSS3/JavaScript | 前端技术 |
| Intersection Observer API | 图片懒加载 |
| DeepSeek API | AI 解读(可替换) |
git clone https://github.com/你的用户名/tarot-project.git
cd tarot-project编辑 backend/src/main/java/com/tarot/service/AIService.java
// 修改这三行即可切换不同的 AI 服务
private static final String API_KEY = "your-api-key";
private static final String API_URL = "https://api.deepseek.com/v1/chat/completions";
private static final String MODEL = "deepseek-chat";cd backend
mvn spring-boot:run控制台出现以下信息表示启动成功:
Tomcat started on port(s): 8081 (http)
塔罗牌后端服务已启动: http://localhost:8081
- 开发环境:使用 VS Code Live Server 打开
frontend/index.html - 生产环境:将
frontend目录部署到任意静态服务器
只需修改 AIService.java 中的三个常量即可:
| 参数 | 说明 |
|---|---|
| API_KEY | 你的 API 密钥 |
| API_URL | API 接口地址 |
| MODEL | 模型名称 |
| AI 服务 | API_URL | MODEL |
|---|---|---|
| DeepSeek | https://api.deepseek.com/v1/chat/completions |
deepseek-chat |
| OpenAI | https://api.openai.com/v1/chat/completions |
gpt-3.5-turbo |
| 智谱 AI | https://open.bigmodel.cn/api/paas/v4/chat/completions |
glm-4 |
| 通义千问 | https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions |
qwen-turbo |
| 本地 Ollama | http://localhost:11434/v1/chat/completions |
llama2 |
💡 不配置 API Key 时,系统会自动降级为模拟解读模式。
tarot-project/
├── backend/
│ ├── src/main/java/com/tarot/
│ │ ├── TarotApplication.java
│ │ ├── controller/
│ │ │ ├── TarotController.java
│ │ │ └── AIController.java
│ │ ├── service/
│ │ │ ├── TarotService.java
│ │ │ └── AIService.java
│ │ └── model/
│ │ └── Card.java
│ ├── src/main/resources/
│ │ └── application.properties
│ └── pom.xml
├── frontend/
│ ├── index.html
│ ├── css/
│ │ └── style.css
│ ├── js/
│ │ ├── script.js
│ │ └── tarot-images.js
│ └── images/ # 图片文件夹(详见下方说明)
└── README.md
本项目使用私人塔罗牌稿件,不包含在开源代码中,但保留了完整的文件夹结构。
frontend/images/
├── major/
│ ├── 正位/
│ └── 逆位/
├── minor/
│ ├── 权杖/
│ │ ├── 正位/
│ │ └── 逆位/
│ ├── 圣杯/
│ │ ├── 正位/
│ │ └── 逆位/
│ ├── 宝剑/
│ │ ├── 正位/
│ │ └── 逆位/
│ └── 星币/
│ ├── 正位/
│ └── 逆位/
└── 卡背/
- 按上述结构放置图片
- 命名规则:
0-愚人.png或1-魔法师.jpg等 - 建议使用 WebP 格式,单张控制在 50KB 以内
- 记得移除里面的temp.txt这是为了上传骨架被迫留下的,我是第一次上传,所以只能这样
完全不放置图片也不影响功能,系统会自动降级为文字卡片显示。
URL:POST /api/tarot/draw
请求体:
{
"deckType": 3,
"drawCount": 3
}| 参数 | 类型 | 说明 |
|---|---|---|
| deckType | int | 1:大阿卡那, 2:小阿卡那, 3:全部 |
| drawCount | int | 抽取数量(1-78) |
响应:
{
"success": true,
"cards": [
{
"name": "愚者",
"type": "大阿卡那",
"upright": true,
"meaning": "新的开始、冒险、天真、自由",
"imageKey": "fool_upright"
}
]
}URL:POST /api/ai/analyze
请求体:
{
"question": "我的感情运势如何?",
"cards": [...],
"spreadType": "three"
}只需修改 AIService.java 中的 API_URL 和 MODEL,其他代码无需改动。
可以,系统会自动降级为模拟解读,功能完整可用。
- 已实现卡背占位 + 懒加载
- 建议将图片压缩到 50KB 以下
- 或使用 WebP 格式
编辑 TarotService.java 中的 MEANINGS 静态块。
MIT License
- DeepSeek - AI 服务支持
- 塔罗牌图片为私人稿件
如有问题,欢迎提 Issue