feat: 使用banana模型生成分镜图片,修复数据库列类型问题
- 修改RealAIService.submitTextToImageTask使用nano-banana/nano-banana-hd模型 - 支持根据hdMode参数选择模型(标准/高清) - 修复数据库列类型:将result_url等字段改为TEXT类型以支持Base64图片 - 添加数据库修复SQL脚本(fix_database_columns.sql, update_database_schema.sql) - 改进StoryboardVideoService的错误处理和空值检查 - 添加GlobalExceptionHandler全局异常处理 - 优化图片URL提取逻辑,支持url和b64_json两种格式 - 改进响应格式验证,确保data字段不为空
This commit is contained in:
@@ -213,3 +213,6 @@ ngrok http 8080
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -108,3 +108,6 @@
|
|||||||
- 类型转换警告
|
- 类型转换警告
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -274,3 +274,6 @@ if (result.success) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
89
demo/FRP_QUICK_START.md
Normal file
89
demo/FRP_QUICK_START.md
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
# FRP 快速开始指南
|
||||||
|
|
||||||
|
## 最简单的配置方法(使用 OpenFrp)
|
||||||
|
|
||||||
|
### 1. 注册并创建隧道
|
||||||
|
|
||||||
|
1. 访问:https://www.openfrp.net/
|
||||||
|
2. 注册账号并登录
|
||||||
|
3. 点击"创建隧道"
|
||||||
|
4. 配置:
|
||||||
|
- 节点:选择国内节点
|
||||||
|
- 类型:HTTP
|
||||||
|
- 本地端口:8080
|
||||||
|
- 域名:使用系统分配的或自定义
|
||||||
|
5. 创建成功后,记录:
|
||||||
|
- 访问地址(如:`https://xxx.openfrp.net`)
|
||||||
|
- 服务器地址
|
||||||
|
- Token
|
||||||
|
|
||||||
|
### 2. 下载 FRP 客户端
|
||||||
|
|
||||||
|
1. 访问:https://github.com/fatedier/frp/releases
|
||||||
|
2. 下载最新版本的 Windows 版本(如:`frp_0.52.3_windows_amd64.zip`)
|
||||||
|
3. 解压到 `demo` 目录
|
||||||
|
|
||||||
|
### 3. 配置 FRP 客户端
|
||||||
|
|
||||||
|
1. 在 `demo` 目录下创建 `frpc.ini` 文件
|
||||||
|
2. 复制 `frpc.ini.example` 的内容
|
||||||
|
3. 修改配置:
|
||||||
|
```ini
|
||||||
|
[common]
|
||||||
|
server_addr = 从OpenFrp控制台获取
|
||||||
|
server_port = 7000
|
||||||
|
token = 从OpenFrp控制台获取
|
||||||
|
|
||||||
|
[payment]
|
||||||
|
type = http
|
||||||
|
local_ip = 127.0.0.1
|
||||||
|
local_port = 8080
|
||||||
|
custom_domains = 你的域名.openfrp.net
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 启动 FRP
|
||||||
|
|
||||||
|
双击运行 `start-frpc.bat`,或手动运行:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
cd demo
|
||||||
|
.\frpc.exe -c frpc.ini
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. 更新配置文件
|
||||||
|
|
||||||
|
更新以下文件中的回调URL:
|
||||||
|
|
||||||
|
**`demo/src/main/resources/application-dev.properties`:**
|
||||||
|
```properties
|
||||||
|
alipay.notify-url=https://你的域名.openfrp.net/api/payments/alipay/notify
|
||||||
|
alipay.return-url=https://你的域名.openfrp.net/api/payments/alipay/return
|
||||||
|
```
|
||||||
|
|
||||||
|
**`demo/src/main/resources/payment.properties`:**
|
||||||
|
```properties
|
||||||
|
alipay.domain=https://你的域名.openfrp.net
|
||||||
|
alipay.notify-url=https://你的域名.openfrp.net/api/payments/alipay/notify
|
||||||
|
alipay.return-url=https://你的域名.openfrp.net/api/payments/alipay/return
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. 重启服务器
|
||||||
|
|
||||||
|
重启 Spring Boot 应用,新的回调地址就会生效。
|
||||||
|
|
||||||
|
### 7. 测试
|
||||||
|
|
||||||
|
1. 访问 `https://你的域名.openfrp.net` - 应该能看到应用
|
||||||
|
2. 测试回调接口:
|
||||||
|
```powershell
|
||||||
|
Invoke-WebRequest -Uri "https://你的域名.openfrp.net/api/payments/alipay/notify" -Method HEAD
|
||||||
|
```
|
||||||
|
应该返回 200,而不是 302
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
- FRP 客户端需要一直运行,关闭后内网穿透会断开
|
||||||
|
- 免费服务可能有流量限制,建议用于开发测试
|
||||||
|
- 生产环境建议使用固定域名和服务器
|
||||||
|
|
||||||
|
|
||||||
@@ -227,3 +227,6 @@ A: IJPay 是对原生 SDK 的封装,提供了更简洁的 API。底层实现
|
|||||||
- 支付宝开放平台:https://open.alipay.com
|
- 支付宝开放平台:https://open.alipay.com
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -294,3 +294,6 @@ grep "img2vid_abc123def456" logs/application.log
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -295,3 +295,6 @@ public TaskQueue addTextToVideoTask(String username, String taskId) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ public class PasswordChecker {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -286,3 +286,6 @@ ResourceNotFound.TemplateNotFound
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -304,3 +304,6 @@ const startPolling = (taskId) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -174,3 +174,6 @@ const updateWork = async (workId, updateData) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
40
demo/fix_database_columns.sql
Normal file
40
demo/fix_database_columns.sql
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
-- 修复数据库列类型:将 VARCHAR 改为 TEXT 以支持 Base64 图片数据
|
||||||
|
-- 执行前请先备份数据库!
|
||||||
|
|
||||||
|
USE aigc_platform;
|
||||||
|
|
||||||
|
-- 检查当前列类型(可选,用于查看当前状态)
|
||||||
|
-- DESCRIBE storyboard_video_tasks;
|
||||||
|
|
||||||
|
-- 更新 storyboard_video_tasks 表
|
||||||
|
ALTER TABLE storyboard_video_tasks
|
||||||
|
MODIFY COLUMN result_url TEXT COMMENT '分镜图结果URL(Base64编码)',
|
||||||
|
MODIFY COLUMN image_url TEXT COMMENT '参考图片URL',
|
||||||
|
MODIFY COLUMN prompt TEXT COMMENT '文本描述';
|
||||||
|
|
||||||
|
-- 更新 text_to_video_tasks 表
|
||||||
|
ALTER TABLE text_to_video_tasks
|
||||||
|
MODIFY COLUMN result_url TEXT COMMENT '视频结果URL';
|
||||||
|
|
||||||
|
-- 更新 image_to_video_tasks 表
|
||||||
|
ALTER TABLE image_to_video_tasks
|
||||||
|
MODIFY COLUMN result_url TEXT COMMENT '视频结果URL';
|
||||||
|
|
||||||
|
-- 更新 user_works 表
|
||||||
|
ALTER TABLE user_works
|
||||||
|
MODIFY COLUMN result_url TEXT COMMENT '作品结果URL',
|
||||||
|
MODIFY COLUMN thumbnail_url TEXT COMMENT '缩略图URL',
|
||||||
|
MODIFY COLUMN description TEXT COMMENT '作品描述',
|
||||||
|
MODIFY COLUMN prompt TEXT COMMENT '生成提示词';
|
||||||
|
|
||||||
|
-- 更新 users 表
|
||||||
|
ALTER TABLE users
|
||||||
|
MODIFY COLUMN avatar TEXT COMMENT '用户头像URL';
|
||||||
|
|
||||||
|
-- 验证更新结果(可选)
|
||||||
|
-- DESCRIBE storyboard_video_tasks;
|
||||||
|
-- DESCRIBE text_to_video_tasks;
|
||||||
|
-- DESCRIBE image_to_video_tasks;
|
||||||
|
-- DESCRIBE user_works;
|
||||||
|
-- DESCRIBE users;
|
||||||
|
|
||||||
@@ -436,6 +436,9 @@ MIT License
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
"pinia": "^2.1.6",
|
"pinia": "^2.1.6",
|
||||||
"axios": "^1.5.0",
|
"axios": "^1.5.0",
|
||||||
"element-plus": "^2.3.8",
|
"element-plus": "^2.3.8",
|
||||||
"@element-plus/icons-vue": "^2.1.0"
|
"@element-plus/icons-vue": "^2.1.0",
|
||||||
|
"qrcode": "^1.5.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "^4.3.4",
|
"@vitejs/plugin-vue": "^4.3.4",
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ console.log('App.vue 加载成功')
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -594,6 +594,67 @@ main.with-navbar {
|
|||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 移除 el-dialog 的所有可能的白色边框 */
|
||||||
|
.payment-modal-dialog,
|
||||||
|
.payment-modal-dialog.el-dialog,
|
||||||
|
.payment-modal-dialog.el-dialog--center,
|
||||||
|
.payment-modal-dialog.el-dialog--center.payment-modal,
|
||||||
|
.el-overlay-dialog .payment-modal-dialog,
|
||||||
|
.el-overlay-dialog .payment-modal-dialog.el-dialog,
|
||||||
|
.el-overlay-dialog .payment-modal-dialog.el-dialog--center,
|
||||||
|
.el-overlay-dialog .payment-modal-dialog.el-dialog--center.payment-modal,
|
||||||
|
.el-overlay.payment-modal-overlay.el-modal-dialog .payment-modal-dialog,
|
||||||
|
.el-overlay.payment-modal-overlay.el-modal-dialog .payment-modal-dialog.el-dialog,
|
||||||
|
.el-overlay.payment-modal-overlay.el-modal-dialog .payment-modal-dialog.el-dialog--center,
|
||||||
|
.el-overlay.payment-modal-overlay.el-modal-dialog .payment-modal-dialog.el-dialog--center.payment-modal {
|
||||||
|
background: #000000 !important;
|
||||||
|
background-color: #000000 !important;
|
||||||
|
border: none !important;
|
||||||
|
border-width: 0 !important;
|
||||||
|
border-style: none !important;
|
||||||
|
border-color: transparent !important;
|
||||||
|
outline: none !important;
|
||||||
|
outline-width: 0 !important;
|
||||||
|
outline-style: none !important;
|
||||||
|
outline-color: transparent !important;
|
||||||
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.payment-modal-dialog .el-dialog__body,
|
||||||
|
.payment-modal-dialog .el-dialog__header {
|
||||||
|
background: #000000 !important;
|
||||||
|
background-color: #000000 !important;
|
||||||
|
border: none !important;
|
||||||
|
border-width: 0 !important;
|
||||||
|
border-left: none !important;
|
||||||
|
border-right: none !important;
|
||||||
|
border-top: none !important;
|
||||||
|
border-bottom: none !important;
|
||||||
|
outline: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 全局覆盖所有可能的对话框背景 */
|
||||||
|
.el-overlay.payment-modal-overlay.el-modal-dialog .el-dialog,
|
||||||
|
.el-overlay.payment-modal-overlay.el-modal-dialog .el-dialog.el-dialog--center,
|
||||||
|
.el-overlay.payment-modal-overlay.el-modal-dialog .el-dialog.el-dialog--center.payment-modal,
|
||||||
|
.el-overlay.payment-modal-overlay.el-modal-dialog .payment-modal-dialog,
|
||||||
|
.el-overlay.payment-modal-overlay.el-modal-dialog .payment-modal-dialog.el-dialog,
|
||||||
|
.el-overlay.payment-modal-overlay.el-modal-dialog .payment-modal-dialog.el-dialog--center,
|
||||||
|
.el-overlay.payment-modal-overlay.el-modal-dialog .payment-modal-dialog.el-dialog--center.payment-modal,
|
||||||
|
.el-overlay-dialog .el-dialog.el-dialog--center.payment-modal,
|
||||||
|
.el-overlay-dialog .payment-modal-dialog.el-dialog--center.payment-modal,
|
||||||
|
.el-dialog.el-dialog--center.payment-modal,
|
||||||
|
.payment-modal-dialog.el-dialog.el-dialog--center.payment-modal,
|
||||||
|
/* 使用属性选择器覆盖所有包含 payment-modal 的对话框 */
|
||||||
|
[class*="payment-modal"][class*="el-dialog"],
|
||||||
|
[class*="payment-modal"][class*="el-dialog--center"],
|
||||||
|
.el-dialog[class*="payment-modal"],
|
||||||
|
.payment-modal-dialog[class*="el-dialog"] {
|
||||||
|
background: #000000 !important;
|
||||||
|
background-color: #000000 !important;
|
||||||
|
background-image: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
/* 滚动条样式 */
|
/* 滚动条样式 */
|
||||||
::-webkit-scrollbar {
|
::-webkit-scrollbar {
|
||||||
width: 8px;
|
width: 8px;
|
||||||
|
|||||||
@@ -52,3 +52,8 @@ export const handleAlipayCallback = (params) => {
|
|||||||
export const getPaymentStats = () => {
|
export const getPaymentStats = () => {
|
||||||
return api.get('/payments/stats')
|
return api.get('/payments/stats')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取用户订阅信息
|
||||||
|
export const getUserSubscriptionInfo = () => {
|
||||||
|
return api.get('/payments/subscription/info')
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,8 +9,13 @@ const api = axios.create({
|
|||||||
baseURL: getApiBaseURL(),
|
baseURL: getApiBaseURL(),
|
||||||
timeout: 900000, // 增加到15分钟,适应视频生成时间
|
timeout: 900000, // 增加到15分钟,适应视频生成时间
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
|
maxRedirects: 0, // 不自动跟随重定向,手动处理302
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
validateStatus: function (status) {
|
||||||
|
// 允许所有状态码,包括302,让拦截器处理
|
||||||
|
return status >= 200 && status < 600
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -19,8 +24,11 @@ api.interceptors.request.use(
|
|||||||
(config) => {
|
(config) => {
|
||||||
// 使用JWT认证,添加Authorization头
|
// 使用JWT认证,添加Authorization头
|
||||||
const token = sessionStorage.getItem('token')
|
const token = sessionStorage.getItem('token')
|
||||||
if (token) {
|
if (token && token !== 'null' && token.trim() !== '') {
|
||||||
config.headers.Authorization = `Bearer ${token}`
|
config.headers.Authorization = `Bearer ${token}`
|
||||||
|
console.log('请求拦截器:添加Authorization头,token长度:', token.length)
|
||||||
|
} else {
|
||||||
|
console.warn('请求拦截器:未找到有效的token')
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
},
|
},
|
||||||
@@ -33,6 +41,33 @@ api.interceptors.request.use(
|
|||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
api.interceptors.response.use(
|
api.interceptors.response.use(
|
||||||
(response) => {
|
(response) => {
|
||||||
|
// 检查是否是HTML响应(可能是302重定向的结果)
|
||||||
|
if (response.data && typeof response.data === 'string' && response.data.trim().startsWith('<!DOCTYPE')) {
|
||||||
|
console.error('收到HTML响应,可能是认证失败:', response.config.url)
|
||||||
|
// 清除无效的token并跳转到登录页
|
||||||
|
sessionStorage.removeItem('token')
|
||||||
|
sessionStorage.removeItem('user')
|
||||||
|
// 避免重复跳转
|
||||||
|
if (router.currentRoute.value.path !== '/login') {
|
||||||
|
ElMessage.error('认证失败,请重新登录')
|
||||||
|
router.push('/login')
|
||||||
|
}
|
||||||
|
// 返回错误,让调用方知道这是认证失败
|
||||||
|
return Promise.reject(new Error('认证失败:收到HTML响应'))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查302重定向
|
||||||
|
if (response.status === 302) {
|
||||||
|
console.error('收到302重定向,可能是认证失败:', response.config.url)
|
||||||
|
sessionStorage.removeItem('token')
|
||||||
|
sessionStorage.removeItem('user')
|
||||||
|
if (router.currentRoute.value.path !== '/login') {
|
||||||
|
ElMessage.error('认证失败,请重新登录')
|
||||||
|
router.push('/login')
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error('认证失败:302重定向'))
|
||||||
|
}
|
||||||
|
|
||||||
// 直接返回response,让调用方处理data
|
// 直接返回response,让调用方处理data
|
||||||
return response
|
return response
|
||||||
},
|
},
|
||||||
@@ -40,13 +75,28 @@ api.interceptors.response.use(
|
|||||||
if (error.response) {
|
if (error.response) {
|
||||||
const { status, data } = error.response
|
const { status, data } = error.response
|
||||||
|
|
||||||
|
// 检查响应数据是否是HTML(302重定向的结果)
|
||||||
|
if (data && typeof data === 'string' && data.trim().startsWith('<!DOCTYPE')) {
|
||||||
|
console.error('收到HTML响应(可能是302重定向):', error.config.url)
|
||||||
|
sessionStorage.removeItem('token')
|
||||||
|
sessionStorage.removeItem('user')
|
||||||
|
if (router.currentRoute.value.path !== '/login') {
|
||||||
|
ElMessage.error('认证失败,请重新登录')
|
||||||
|
router.push('/login')
|
||||||
|
}
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 401:
|
case 401:
|
||||||
ElMessage.error('未授权,请重新登录')
|
case 302:
|
||||||
|
// 302也可能是认证失败导致的
|
||||||
sessionStorage.removeItem('token')
|
sessionStorage.removeItem('token')
|
||||||
sessionStorage.removeItem('user')
|
sessionStorage.removeItem('user')
|
||||||
// 使用Vue Router进行路由跳转,避免页面刷新
|
if (router.currentRoute.value.path !== '/login') {
|
||||||
router.push('/login')
|
ElMessage.error('认证失败,请重新登录')
|
||||||
|
router.push('/login')
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case 403:
|
case 403:
|
||||||
ElMessage.error('权限不足')
|
ElMessage.error('权限不足')
|
||||||
|
|||||||
@@ -62,3 +62,6 @@ export const getWorkStats = () => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
:close-on-click-modal="false"
|
:close-on-click-modal="false"
|
||||||
:close-on-press-escape="true"
|
:close-on-press-escape="true"
|
||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
center
|
|
||||||
:show-close="true"
|
:show-close="true"
|
||||||
custom-class="payment-modal-dialog"
|
custom-class="payment-modal-dialog"
|
||||||
|
:modal-class="'payment-modal-overlay'"
|
||||||
>
|
>
|
||||||
<div class="payment-content">
|
<div class="payment-content">
|
||||||
<!-- 支付方式选择 -->
|
<!-- 支付方式选择 -->
|
||||||
@@ -36,8 +36,8 @@
|
|||||||
<!-- 二维码区域 -->
|
<!-- 二维码区域 -->
|
||||||
<div class="qr-section">
|
<div class="qr-section">
|
||||||
<div class="qr-code">
|
<div class="qr-code">
|
||||||
<img id="qr-code-img" style="display: none; width: 200px; height: 200px;" alt="支付二维码" />
|
<img id="qr-code-img" style="display: none; width: 200px; height: 200px; margin: 0; padding: 0; border: none; object-fit: contain; background: #1a1a1a;" alt="支付二维码" />
|
||||||
<div class="qr-placeholder">
|
<div ref="qrPlaceholder" class="qr-placeholder">
|
||||||
<div class="qr-grid">
|
<div class="qr-grid">
|
||||||
<div class="qr-dot" v-for="i in 64" :key="i"></div>
|
<div class="qr-dot" v-for="i in 64" :key="i"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -52,6 +52,26 @@
|
|||||||
<p>请使用支付宝扫描上方二维码完成支付</p>
|
<p>请使用支付宝扫描上方二维码完成支付</p>
|
||||||
<p class="tip-small">支付完成后页面将自动更新</p>
|
<p class="tip-small">支付完成后页面将自动更新</p>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 模拟支付完成按钮(仅用于测试) -->
|
||||||
|
<div class="test-payment-section" style="margin-top: 16px; text-align: center;">
|
||||||
|
<button
|
||||||
|
class="test-payment-btn"
|
||||||
|
@click="handleTestPaymentComplete"
|
||||||
|
:disabled="!currentPaymentId || loading"
|
||||||
|
style="
|
||||||
|
padding: 8px 16px;
|
||||||
|
background: #ff9800;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 12px;
|
||||||
|
opacity: 0.8;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
🧪 模拟支付完成(测试用)
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 底部链接 -->
|
<!-- 底部链接 -->
|
||||||
@@ -63,10 +83,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch, onUnmounted } from 'vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { CreditCard } from '@element-plus/icons-vue'
|
import { CreditCard } from '@element-plus/icons-vue'
|
||||||
import { createPayment, createAlipayPayment } from '@/api/payments'
|
import { createPayment, createAlipayPayment, getPaymentById, testPaymentComplete } from '@/api/payments'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
@@ -92,15 +112,25 @@ const emit = defineEmits(['update:modelValue', 'pay-success', 'pay-error'])
|
|||||||
const visible = ref(false)
|
const visible = ref(false)
|
||||||
const selectedMethod = ref('alipay')
|
const selectedMethod = ref('alipay')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const currentPaymentId = ref(null)
|
||||||
|
let paymentPollingTimer = null
|
||||||
|
|
||||||
// 监听 modelValue 变化
|
// 监听 modelValue 变化
|
||||||
watch(() => props.modelValue, (newVal) => {
|
watch(() => props.modelValue, (newVal) => {
|
||||||
visible.value = newVal
|
visible.value = newVal
|
||||||
|
// 当模态框打开时,自动开始支付流程
|
||||||
|
if (newVal) {
|
||||||
|
handlePay()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听 visible 变化
|
// 监听 visible 变化
|
||||||
watch(visible, (newVal) => {
|
watch(visible, (newVal) => {
|
||||||
emit('update:modelValue', newVal)
|
emit('update:modelValue', newVal)
|
||||||
|
// 如果模态框关闭,停止轮询
|
||||||
|
if (!newVal) {
|
||||||
|
stopPaymentPolling()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 选择支付方式
|
// 选择支付方式
|
||||||
@@ -132,6 +162,7 @@ const handlePay = async () => {
|
|||||||
|
|
||||||
if (createResponse.data && createResponse.data.success) {
|
if (createResponse.data && createResponse.data.success) {
|
||||||
const paymentId = createResponse.data.data.id
|
const paymentId = createResponse.data.data.id
|
||||||
|
currentPaymentId.value = paymentId
|
||||||
console.log('2. 支付订单创建成功,ID:', paymentId)
|
console.log('2. 支付订单创建成功,ID:', paymentId)
|
||||||
|
|
||||||
ElMessage.info('正在生成支付宝二维码...')
|
ElMessage.info('正在生成支付宝二维码...')
|
||||||
@@ -148,24 +179,41 @@ const handlePay = async () => {
|
|||||||
const qrCode = alipayResponse.data.data.qrCode
|
const qrCode = alipayResponse.data.data.qrCode
|
||||||
console.log('4. 支付宝二维码:', qrCode)
|
console.log('4. 支付宝二维码:', qrCode)
|
||||||
|
|
||||||
// 更新二维码显示
|
// 使用在线API生成二维码图片(直接使用支付宝返回的URL生成二维码)
|
||||||
const qrCodeElement = document.querySelector('#qr-code-img')
|
try {
|
||||||
if (qrCodeElement) {
|
console.log('开始生成二维码,内容:', qrCode)
|
||||||
qrCodeElement.src = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(qrCode)}`
|
|
||||||
qrCodeElement.style.display = 'block'
|
// 使用QuickChart API生成二维码,完全去除白边
|
||||||
console.log('5. 二维码图片已设置')
|
// 直接使用支付宝返回的URL作为二维码内容
|
||||||
|
const qrCodeUrl = `https://quickchart.io/qr?text=${encodeURIComponent(qrCode)}&size=200&margin=0&dark=ffffff&light=1a1a1a`
|
||||||
|
|
||||||
|
console.log('5. 二维码图片URL已生成')
|
||||||
|
|
||||||
|
// 更新二维码显示
|
||||||
|
const qrCodeElement = document.querySelector('#qr-code-img')
|
||||||
|
if (qrCodeElement) {
|
||||||
|
qrCodeElement.src = qrCodeUrl
|
||||||
|
qrCodeElement.style.display = 'block'
|
||||||
|
console.log('6. 二维码图片已设置')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 隐藏模拟二维码
|
||||||
|
const qrPlaceholder = document.querySelector('.qr-placeholder')
|
||||||
|
if (qrPlaceholder) {
|
||||||
|
qrPlaceholder.style.display = 'none'
|
||||||
|
console.log('7. 模拟二维码已隐藏')
|
||||||
|
}
|
||||||
|
|
||||||
|
ElMessage.success('二维码已生成,请使用支付宝扫码支付')
|
||||||
|
console.log('=== 支付流程完成,开始轮询支付状态 ===')
|
||||||
|
|
||||||
|
// 开始轮询支付状态
|
||||||
|
startPaymentPolling(paymentId)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('生成二维码失败:', error)
|
||||||
|
ElMessage.error('生成二维码失败,请重试')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏模拟二维码
|
|
||||||
const qrPlaceholder = document.querySelector('.qr-placeholder')
|
|
||||||
if (qrPlaceholder) {
|
|
||||||
qrPlaceholder.style.display = 'none'
|
|
||||||
console.log('6. 模拟二维码已隐藏')
|
|
||||||
}
|
|
||||||
|
|
||||||
ElMessage.success('二维码已生成,请使用支付宝扫码支付')
|
|
||||||
console.log('=== 支付流程完成 ===')
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.error('支付宝响应失败:', alipayResponse)
|
console.error('支付宝响应失败:', alipayResponse)
|
||||||
ElMessage.error(alipayResponse.data?.message || '生成二维码失败')
|
ElMessage.error(alipayResponse.data?.message || '生成二维码失败')
|
||||||
@@ -192,11 +240,152 @@ const handlePay = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 轮询支付状态
|
||||||
|
const startPaymentPolling = (paymentId) => {
|
||||||
|
// 清除之前的轮询
|
||||||
|
stopPaymentPolling()
|
||||||
|
|
||||||
|
let pollCount = 0
|
||||||
|
const maxPolls = 60 // 最多轮询60次(10分钟,每10秒一次)
|
||||||
|
|
||||||
|
const poll = async () => {
|
||||||
|
if (pollCount >= maxPolls) {
|
||||||
|
console.log('轮询达到最大次数,停止轮询')
|
||||||
|
stopPaymentPolling()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(`轮询支付状态 (${pollCount + 1}/${maxPolls}),支付ID:`, paymentId)
|
||||||
|
const response = await getPaymentById(paymentId)
|
||||||
|
|
||||||
|
if (response.data && response.data.success) {
|
||||||
|
const payment = response.data.data
|
||||||
|
const status = payment.status
|
||||||
|
console.log('支付状态:', status, '状态说明:', getStatusDescription(status))
|
||||||
|
|
||||||
|
if (status === 'SUCCESS' || status === 'COMPLETED') {
|
||||||
|
console.log('✅ 支付成功!支付数据:', payment)
|
||||||
|
stopPaymentPolling()
|
||||||
|
ElMessage.success('支付成功!')
|
||||||
|
emit('pay-success', payment)
|
||||||
|
// 延迟关闭模态框
|
||||||
|
setTimeout(() => {
|
||||||
|
visible.value = false
|
||||||
|
}, 2000)
|
||||||
|
return
|
||||||
|
} else if (status === 'FAILED' || status === 'CANCELLED') {
|
||||||
|
console.log('支付失败或取消')
|
||||||
|
stopPaymentPolling()
|
||||||
|
ElMessage.warning('支付已取消或失败')
|
||||||
|
emit('pay-error', new Error('支付已取消或失败'))
|
||||||
|
return
|
||||||
|
} else if (status === 'PROCESSING') {
|
||||||
|
console.log('支付处理中...')
|
||||||
|
// PROCESSING 状态继续轮询,但可以给用户提示
|
||||||
|
if (pollCount % 6 === 0) { // 每60秒提示一次
|
||||||
|
ElMessage.info('支付处理中,请稍候...')
|
||||||
|
}
|
||||||
|
} else if (status === 'PENDING') {
|
||||||
|
console.log('支付待处理中(等待支付宝回调)...')
|
||||||
|
// PENDING 状态继续轮询
|
||||||
|
if (pollCount % 6 === 0) { // 每60秒提示一次
|
||||||
|
ElMessage.info('等待支付确认,请确保已完成支付...')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 继续轮询
|
||||||
|
pollCount++
|
||||||
|
paymentPollingTimer = setTimeout(poll, 10000) // 每10秒轮询一次
|
||||||
|
} catch (error) {
|
||||||
|
console.error('轮询支付状态失败:', error)
|
||||||
|
// 错误时也继续轮询,直到达到最大次数
|
||||||
|
pollCount++
|
||||||
|
if (pollCount < maxPolls) {
|
||||||
|
paymentPollingTimer = setTimeout(poll, 10000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始轮询(等待5秒后开始第一次轮询)
|
||||||
|
setTimeout(() => {
|
||||||
|
poll()
|
||||||
|
}, 5000)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 停止轮询支付状态
|
||||||
|
const stopPaymentPolling = () => {
|
||||||
|
if (paymentPollingTimer) {
|
||||||
|
clearTimeout(paymentPollingTimer)
|
||||||
|
paymentPollingTimer = null
|
||||||
|
console.log('已停止轮询支付状态')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 关闭模态框
|
// 关闭模态框
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
|
stopPaymentPolling()
|
||||||
visible.value = false
|
visible.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 组件卸载时清理轮询
|
||||||
|
onUnmounted(() => {
|
||||||
|
stopPaymentPolling()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 获取支付状态描述
|
||||||
|
const getStatusDescription = (status) => {
|
||||||
|
const statusMap = {
|
||||||
|
'PENDING': '待支付 - 等待用户扫码支付',
|
||||||
|
'PROCESSING': '处理中 - 支付宝正在处理支付',
|
||||||
|
'SUCCESS': '支付成功',
|
||||||
|
'COMPLETED': '支付完成',
|
||||||
|
'FAILED': '支付失败',
|
||||||
|
'CANCELLED': '已取消',
|
||||||
|
'REFUNDED': '已退款'
|
||||||
|
}
|
||||||
|
return statusMap[status] || '未知状态'
|
||||||
|
}
|
||||||
|
|
||||||
|
// 模拟支付完成(用于测试)
|
||||||
|
const handleTestPaymentComplete = async () => {
|
||||||
|
if (!currentPaymentId.value) {
|
||||||
|
ElMessage.warning('支付订单尚未创建,请稍候...')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
loading.value = true
|
||||||
|
ElMessage.info('正在模拟支付完成...')
|
||||||
|
|
||||||
|
console.log('模拟支付完成,支付ID:', currentPaymentId.value)
|
||||||
|
const response = await testPaymentComplete(currentPaymentId.value)
|
||||||
|
|
||||||
|
console.log('✅ 模拟支付完成响应:', response)
|
||||||
|
console.log('✅ 响应数据:', response.data)
|
||||||
|
|
||||||
|
if (response.data && response.data.success) {
|
||||||
|
console.log('✅ 模拟支付完成成功,支付数据:', response.data.data)
|
||||||
|
ElMessage.success('支付完成!')
|
||||||
|
stopPaymentPolling()
|
||||||
|
emit('pay-success', response.data.data)
|
||||||
|
// 延迟关闭模态框
|
||||||
|
setTimeout(() => {
|
||||||
|
visible.value = false
|
||||||
|
}, 2000)
|
||||||
|
} else {
|
||||||
|
console.error('❌ 模拟支付完成失败,响应:', response)
|
||||||
|
ElMessage.error(response.data?.message || '模拟支付完成失败')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('模拟支付完成失败:', error)
|
||||||
|
ElMessage.error(`模拟支付完成失败:${error.message || '请重试'}`)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 显示协议
|
// 显示协议
|
||||||
const showAgreement = () => {
|
const showAgreement = () => {
|
||||||
ElMessage.info('服务协议页面')
|
ElMessage.info('服务协议页面')
|
||||||
@@ -205,76 +394,256 @@ const showAgreement = () => {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.payment-modal {
|
.payment-modal {
|
||||||
background: #0a0a0a;
|
background: #000000 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 移除所有可能的白边和边框 */
|
/* 移除所有可能的白边和边框 */
|
||||||
.payment-modal :deep(.el-dialog),
|
.payment-modal :deep(.el-dialog),
|
||||||
.payment-modal-dialog {
|
.payment-modal-dialog,
|
||||||
background: #0a0a0a !important;
|
.payment-modal :deep(.el-dialog.el-dialog--center.payment-modal),
|
||||||
border-radius: 12px;
|
.payment-modal :deep(.el-dialog.el-dialog--center),
|
||||||
|
.payment-modal.el-dialog.el-dialog--center.payment-modal,
|
||||||
|
.payment-modal :deep(.el-dialog.el-dialog--center.payment-modal-dialog),
|
||||||
|
.payment-modal :deep(.payment-modal-dialog.el-dialog.el-dialog--center.payment-modal) {
|
||||||
|
background: #000000 !important;
|
||||||
|
background-color: #000000 !important;
|
||||||
|
background-image: none !important;
|
||||||
|
border-radius: 12px !important;
|
||||||
border: none !important;
|
border: none !important;
|
||||||
border-width: 0 !important;
|
border-width: 0 !important;
|
||||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
|
border-style: none !important;
|
||||||
|
border-color: transparent !important;
|
||||||
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), inset 0 0 0 0 transparent !important;
|
||||||
padding: 0 !important;
|
padding: 0 !important;
|
||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
outline: none !important;
|
outline: none !important;
|
||||||
|
outline-width: 0 !important;
|
||||||
|
outline-style: none !important;
|
||||||
|
outline-color: transparent !important;
|
||||||
box-sizing: border-box !important;
|
box-sizing: border-box !important;
|
||||||
overflow: hidden !important;
|
overflow: hidden !important;
|
||||||
|
/* 移除所有可能的白色边框 */
|
||||||
|
-webkit-box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), inset 0 0 0 0 transparent !important;
|
||||||
|
-moz-box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), inset 0 0 0 0 transparent !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 移除所有伪元素可能产生的边框 */
|
||||||
|
.payment-modal :deep(.el-dialog::before),
|
||||||
|
.payment-modal :deep(.el-dialog::after),
|
||||||
|
.payment-modal :deep(.el-dialog__wrapper::before),
|
||||||
|
.payment-modal :deep(.el-dialog__wrapper::after),
|
||||||
|
.payment-modal :deep(.el-dialog__body::before),
|
||||||
|
.payment-modal :deep(.el-dialog__body::after) {
|
||||||
|
display: none !important;
|
||||||
|
content: none !important;
|
||||||
|
border: none !important;
|
||||||
|
outline: none !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 移除所有可能的白色边框 - 使用更具体的选择器 */
|
||||||
|
.payment-modal :deep(.el-dialog),
|
||||||
|
.payment-modal :deep(.el-dialog *) {
|
||||||
|
border-left: none !important;
|
||||||
|
border-right: none !important;
|
||||||
|
border-top: none !important;
|
||||||
|
border-bottom: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.payment-modal :deep(.el-dialog__body) {
|
.payment-modal :deep(.el-dialog__body) {
|
||||||
padding: 0 !important;
|
padding: 0 !important;
|
||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
background: #0a0a0a !important;
|
background: #000000 !important;
|
||||||
|
background-color: #000000 !important;
|
||||||
border: none !important;
|
border: none !important;
|
||||||
|
border-width: 0 !important;
|
||||||
|
border-style: none !important;
|
||||||
|
border-color: transparent !important;
|
||||||
|
outline: none !important;
|
||||||
|
outline-width: 0 !important;
|
||||||
|
outline-style: none !important;
|
||||||
|
outline-color: transparent !important;
|
||||||
overflow: hidden !important;
|
overflow: hidden !important;
|
||||||
|
box-sizing: border-box !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 移除对话框内部的所有边框和间隙 */
|
||||||
|
.payment-modal :deep(.el-dialog) * {
|
||||||
|
border-color: transparent !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 确保对话框本身没有任何白色背景或边框 */
|
||||||
|
.payment-modal :deep(.el-dialog),
|
||||||
|
.payment-modal :deep(.el-dialog.el-dialog--center.payment-modal),
|
||||||
|
.payment-modal :deep(.el-dialog.el-dialog--center),
|
||||||
|
.payment-modal :deep(.payment-modal-dialog),
|
||||||
|
.payment-modal :deep(.payment-modal-dialog.el-dialog),
|
||||||
|
.payment-modal :deep(.payment-modal-dialog.el-dialog--center),
|
||||||
|
.payment-modal :deep(.payment-modal-dialog.el-dialog--center.payment-modal) {
|
||||||
|
background-color: #000000 !important;
|
||||||
|
background: #000000 !important;
|
||||||
|
background-image: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 移除所有可能的白色边框 */
|
||||||
|
.payment-modal :deep(.el-dialog),
|
||||||
|
.payment-modal :deep(.el-dialog__body) {
|
||||||
|
border: 0 !important;
|
||||||
|
border-top: none !important;
|
||||||
|
border-bottom: none !important;
|
||||||
|
border-left: none !important;
|
||||||
|
border-right: none !important;
|
||||||
|
border-width: 0 !important;
|
||||||
|
border-style: none !important;
|
||||||
|
border-color: transparent !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.payment-modal :deep(.el-dialog__header),
|
||||||
|
.payment-modal :deep(.el-dialog__header.show-close) {
|
||||||
|
background: #000000 !important;
|
||||||
|
background-color: #000000 !important;
|
||||||
|
border: none !important;
|
||||||
|
border-bottom: 1px solid #1a1a1a !important;
|
||||||
|
border-top: none !important;
|
||||||
|
border-left: none !important;
|
||||||
|
border-right: none !important;
|
||||||
|
border-width: 0 !important;
|
||||||
|
border-bottom-width: 1px !important;
|
||||||
|
border-bottom-style: solid !important;
|
||||||
|
border-bottom-color: #1a1a1a !important;
|
||||||
|
padding: 20px 24px !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
color: white !important;
|
||||||
|
text-align: left !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 确保 header.show-close 内的所有文字都是白色 */
|
||||||
|
.payment-modal :deep(.el-dialog__header.show-close),
|
||||||
|
.payment-modal :deep(.el-dialog__header.show-close *),
|
||||||
|
.payment-modal :deep(.el-dialog__header.show-close .el-dialog__title),
|
||||||
|
.payment-modal :deep(.el-dialog__header.show-close .el-dialog__headerbtn) {
|
||||||
|
color: white !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 确保关闭按钮区域背景也与模态框一致 */
|
||||||
|
.payment-modal :deep(.el-dialog__headerbtn),
|
||||||
|
.payment-modal :deep(.el-dialog__headerbtn.is-close),
|
||||||
|
.payment-modal :deep(.el-dialog__header .el-dialog__headerbtn) {
|
||||||
|
background: transparent !important;
|
||||||
|
background-color: transparent !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.payment-modal :deep(.el-dialog__headerbtn:hover) {
|
||||||
|
background: rgba(255, 255, 255, 0.1) !important;
|
||||||
|
background-color: rgba(255, 255, 255, 0.1) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.payment-modal :deep(.el-dialog__wrapper) {
|
.payment-modal :deep(.el-dialog__wrapper) {
|
||||||
background: transparent !important;
|
|
||||||
padding: 0 !important;
|
padding: 0 !important;
|
||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
|
border: none !important;
|
||||||
|
border-width: 0 !important;
|
||||||
|
border-style: none !important;
|
||||||
|
border-color: transparent !important;
|
||||||
|
outline: none !important;
|
||||||
|
outline-width: 0 !important;
|
||||||
|
outline-style: none !important;
|
||||||
|
outline-color: transparent !important;
|
||||||
|
background: transparent !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.payment-modal :deep(.el-overlay) {
|
/* 确保 wrapper 内的所有对话框元素背景为黑色 */
|
||||||
background: transparent !important;
|
.payment-modal :deep(.el-dialog__wrapper .el-dialog),
|
||||||
|
.payment-modal :deep(.el-dialog__wrapper .el-dialog.el-dialog--center),
|
||||||
|
.payment-modal :deep(.el-dialog__wrapper .el-dialog.el-dialog--center.payment-modal),
|
||||||
|
.payment-modal :deep(.el-dialog__wrapper .payment-modal-dialog) {
|
||||||
|
background: #000000 !important;
|
||||||
|
background-color: #000000 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.payment-modal :deep(.el-overlay),
|
||||||
|
.payment-modal :deep(.payment-modal-overlay),
|
||||||
|
.payment-modal :deep(.el-overlay.payment-modal-overlay),
|
||||||
|
.payment-modal :deep(.el-overlay.payment-modal-overlay.el-modal-dialog) {
|
||||||
|
background: rgba(0, 0, 0, 0.5) !important;
|
||||||
|
border: none !important;
|
||||||
|
outline: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 确保 el-overlay.payment-modal-overlay.el-modal-dialog 内的对话框背景为黑色 */
|
||||||
|
.payment-modal :deep(.el-overlay.payment-modal-overlay.el-modal-dialog .el-dialog),
|
||||||
|
.payment-modal :deep(.el-overlay.payment-modal-overlay.el-modal-dialog .el-dialog.el-dialog--center),
|
||||||
|
.payment-modal :deep(.el-overlay.payment-modal-overlay.el-modal-dialog .el-dialog.el-dialog--center.payment-modal),
|
||||||
|
.payment-modal :deep(.el-overlay.payment-modal-overlay.el-modal-dialog .el-dialog__body),
|
||||||
|
.payment-modal :deep(.el-overlay.payment-modal-overlay.el-modal-dialog .el-dialog__header) {
|
||||||
|
background: #000000 !important;
|
||||||
|
background-color: #000000 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.payment-modal :deep(.el-overlay-dialog) {
|
.payment-modal :deep(.el-overlay-dialog) {
|
||||||
background: transparent !important;
|
background: rgba(0, 0, 0, 0.5) !important;
|
||||||
|
border: none !important;
|
||||||
|
outline: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 确保 el-overlay-dialog 内的对话框背景为黑色 */
|
||||||
|
.payment-modal :deep(.el-overlay-dialog .el-dialog),
|
||||||
|
.payment-modal :deep(.el-overlay-dialog .el-dialog.el-dialog--center),
|
||||||
|
.payment-modal :deep(.el-overlay-dialog .el-dialog.el-dialog--center.payment-modal),
|
||||||
|
.payment-modal :deep(.el-overlay-dialog .el-dialog__body),
|
||||||
|
.payment-modal :deep(.el-overlay-dialog .el-dialog__header) {
|
||||||
|
background: #000000 !important;
|
||||||
|
background-color: #000000 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 确保遮罩层没有白边 */
|
/* 确保遮罩层没有白边 */
|
||||||
.payment-modal :deep(.el-overlay.is-message-box) {
|
.payment-modal :deep(.el-overlay.is-message-box) {
|
||||||
background: transparent !important;
|
background: rgba(0, 0, 0, 0.5) !important;
|
||||||
}
|
|
||||||
|
|
||||||
.payment-modal :deep(.el-dialog__header) {
|
|
||||||
background: #0a0a0a;
|
|
||||||
border-bottom: 1px solid #1a1a1a;
|
|
||||||
padding: 20px 24px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.payment-modal :deep(.el-dialog__title) {
|
.payment-modal :deep(.el-dialog__title) {
|
||||||
color: white;
|
color: #ffffff !important;
|
||||||
font-size: 18px;
|
font-size: 18px !important;
|
||||||
font-weight: 600;
|
font-weight: bold !important;
|
||||||
|
font-family: "SimSun", "宋体", serif !important;
|
||||||
|
text-align: left !important;
|
||||||
|
line-height: 1.5 !important;
|
||||||
|
letter-spacing: 0.5px !important;
|
||||||
|
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8), 0 0 10px rgba(255, 255, 255, 0.3) !important;
|
||||||
|
filter: brightness(1.1) contrast(1.2) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.payment-modal :deep(.el-dialog__headerbtn) {
|
.payment-modal :deep(.el-dialog__headerbtn) {
|
||||||
color: #999;
|
color: white !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.payment-modal :deep(.el-dialog__headerbtn:hover) {
|
.payment-modal :deep(.el-dialog__headerbtn:hover) {
|
||||||
color: white;
|
color: white !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.payment-modal :deep(.el-dialog__headerbtn svg) {
|
||||||
|
color: white !important;
|
||||||
|
fill: white !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.payment-content {
|
.payment-content {
|
||||||
padding: 24px;
|
padding: 24px;
|
||||||
background: #0a0a0a;
|
background: #000000 !important;
|
||||||
color: white;
|
background-color: #000000 !important;
|
||||||
margin: 0;
|
color: white !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
border: none !important;
|
||||||
|
border-width: 0 !important;
|
||||||
|
box-sizing: border-box !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 确保 payment-content 内的所有文字都是白色(链接除外) */
|
||||||
|
.payment-content,
|
||||||
|
.payment-content *:not(a),
|
||||||
|
.payment-content p,
|
||||||
|
.payment-content span,
|
||||||
|
.payment-content div {
|
||||||
|
color: white !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 支付方式选择 */
|
/* 支付方式选择 */
|
||||||
@@ -296,6 +665,7 @@ const showAgreement = () => {
|
|||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
background: #1a1a1a;
|
background: #1a1a1a;
|
||||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
||||||
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.payment-method:hover {
|
.payment-method:hover {
|
||||||
@@ -323,8 +693,11 @@ const showAgreement = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.payment-method span {
|
.payment-method span {
|
||||||
font-size: 14px;
|
font-size: 14px !important;
|
||||||
font-weight: 500;
|
font-weight: 500 !important;
|
||||||
|
color: white !important;
|
||||||
|
line-height: 1.5 !important;
|
||||||
|
letter-spacing: 0.3px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 金额显示 */
|
/* 金额显示 */
|
||||||
@@ -334,16 +707,21 @@ const showAgreement = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.amount-label {
|
.amount-label {
|
||||||
font-size: 14px;
|
font-size: 14px !important;
|
||||||
color: #999;
|
color: white !important;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px !important;
|
||||||
|
font-weight: 400 !important;
|
||||||
|
line-height: 1.5 !important;
|
||||||
|
letter-spacing: 0.3px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.amount-value {
|
.amount-value {
|
||||||
font-size: 32px;
|
font-size: 32px !important;
|
||||||
font-weight: 700;
|
font-weight: 700 !important;
|
||||||
color: #e0e0e0;
|
color: white !important;
|
||||||
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
|
||||||
|
line-height: 1.2 !important;
|
||||||
|
letter-spacing: 0.5px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 二维码区域 */
|
/* 二维码区域 */
|
||||||
@@ -356,13 +734,30 @@ const showAgreement = () => {
|
|||||||
width: 200px;
|
width: 200px;
|
||||||
height: 200px;
|
height: 200px;
|
||||||
margin: 0 auto 16px;
|
margin: 0 auto 16px;
|
||||||
|
padding: 0;
|
||||||
background: #1a1a1a;
|
background: #1a1a1a;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
|
||||||
|
overflow: hidden;
|
||||||
|
box-sizing: border-box;
|
||||||
|
position: relative;
|
||||||
|
line-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr-code img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: none;
|
||||||
|
display: block;
|
||||||
|
object-fit: contain;
|
||||||
|
object-position: center;
|
||||||
|
background: #1a1a1a;
|
||||||
|
box-sizing: border-box;
|
||||||
|
image-rendering: -webkit-optimize-contrast;
|
||||||
|
image-rendering: crisp-edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
.qr-placeholder {
|
.qr-placeholder {
|
||||||
@@ -409,15 +804,20 @@ const showAgreement = () => {
|
|||||||
top: 50%;
|
top: 50%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translate(-50%, calc(-50% + 40px));
|
transform: translate(-50%, calc(-50% + 40px));
|
||||||
color: #4a9eff;
|
color: white !important;
|
||||||
font-size: 12px;
|
font-size: 12px !important;
|
||||||
font-weight: 500;
|
font-weight: 500 !important;
|
||||||
opacity: 0.8;
|
opacity: 0.8 !important;
|
||||||
|
line-height: 1.5 !important;
|
||||||
|
letter-spacing: 0.3px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.qr-tip {
|
.qr-tip {
|
||||||
font-size: 12px;
|
font-size: 12px !important;
|
||||||
color: #999;
|
color: white !important;
|
||||||
|
line-height: 1.5 !important;
|
||||||
|
letter-spacing: 0.2px !important;
|
||||||
|
font-weight: 400 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 操作按钮 */
|
/* 操作按钮 */
|
||||||
@@ -469,14 +869,21 @@ const showAgreement = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.pay-tip p {
|
.pay-tip p {
|
||||||
margin: 8px 0;
|
margin: 8px 0 !important;
|
||||||
color: #e0e0e0;
|
color: white !important;
|
||||||
font-size: 14px;
|
font-size: 14px !important;
|
||||||
|
line-height: 1.6 !important;
|
||||||
|
letter-spacing: 0.3px !important;
|
||||||
|
font-weight: 400 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tip-small {
|
.tip-small {
|
||||||
color: #999 !important;
|
color: white !important;
|
||||||
font-size: 12px !important;
|
font-size: 12px !important;
|
||||||
|
line-height: 1.5 !important;
|
||||||
|
letter-spacing: 0.2px !important;
|
||||||
|
font-weight: 400 !important;
|
||||||
|
opacity: 0.8 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 底部链接 */
|
/* 底部链接 */
|
||||||
@@ -485,14 +892,17 @@ const showAgreement = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.footer-link a {
|
.footer-link a {
|
||||||
color: #4a9eff;
|
color: #4a9eff !important;
|
||||||
text-decoration: none;
|
text-decoration: none !important;
|
||||||
font-size: 12px;
|
font-size: 12px !important;
|
||||||
transition: color 0.3s ease;
|
transition: color 0.3s ease !important;
|
||||||
|
line-height: 1.5 !important;
|
||||||
|
letter-spacing: 0.2px !important;
|
||||||
|
font-weight: 400 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer-link a:hover {
|
.footer-link a:hover {
|
||||||
color: #3a8bdf;
|
color: #3a8bdf !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 响应式设计 */
|
/* 响应式设计 */
|
||||||
|
|||||||
@@ -89,7 +89,8 @@ const routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
redirect: '/profile' // 重定向到个人主页
|
name: 'Root',
|
||||||
|
redirect: '/welcome' // 默认重定向到欢迎页面
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/welcome',
|
path: '/welcome',
|
||||||
@@ -230,6 +231,19 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
await userStore.init()
|
await userStore.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理根路径:如果已登录,重定向到个人主页;否则重定向到欢迎页面
|
||||||
|
if (to.path === '/' || to.path === '/welcome') {
|
||||||
|
if (userStore.isAuthenticated && to.path === '/') {
|
||||||
|
next('/profile')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 未登录用户访问欢迎页面,允许访问
|
||||||
|
if (!userStore.isAuthenticated && to.path === '/welcome') {
|
||||||
|
next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 检查是否需要认证
|
// 检查是否需要认证
|
||||||
if (to.meta.requiresAuth) {
|
if (to.meta.requiresAuth) {
|
||||||
if (!userStore.isAuthenticated) {
|
if (!userStore.isAuthenticated) {
|
||||||
|
|||||||
@@ -34,6 +34,10 @@
|
|||||||
class="email-input"
|
class="email-input"
|
||||||
type="email"
|
type="email"
|
||||||
/>
|
/>
|
||||||
|
<!-- 快捷输入标签 -->
|
||||||
|
<div class="quick-email-tags">
|
||||||
|
<span class="email-tag" @click="fillQuickEmail('984523799@qq.com')">984523799@qq.com</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 验证码输入 -->
|
<!-- 验证码输入 -->
|
||||||
@@ -127,10 +131,20 @@ const fillTestAccount = (email, code) => {
|
|||||||
loginForm.code = code
|
loginForm.code = code
|
||||||
}
|
}
|
||||||
|
|
||||||
// 组件挂载时设置默认测试账号
|
// 快速填充邮箱(快捷输入)
|
||||||
|
const fillQuickEmail = (email) => {
|
||||||
|
loginForm.email = email
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组件挂载时设置默认测试账号或从URL参数读取邮箱
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 设置默认的测试邮箱
|
// 从URL参数中读取邮箱
|
||||||
loginForm.email = 'admin@example.com'
|
if (route.query.email) {
|
||||||
|
loginForm.email = route.query.email
|
||||||
|
} else {
|
||||||
|
// 设置默认的测试邮箱
|
||||||
|
loginForm.email = 'admin@example.com'
|
||||||
|
}
|
||||||
// 不设置验证码,让用户手动输入
|
// 不设置验证码,让用户手动输入
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -423,6 +437,33 @@ const handleLogin = async () => {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 快捷输入标签 */
|
||||||
|
.quick-email-tags {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
margin-top: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.email-tag {
|
||||||
|
background: rgba(64, 158, 255, 0.15);
|
||||||
|
border: 1px solid rgba(64, 158, 255, 0.3);
|
||||||
|
color: rgba(255, 255, 255, 0.9);
|
||||||
|
padding: 6px 12px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.email-tag:hover {
|
||||||
|
background: rgba(64, 158, 255, 0.25);
|
||||||
|
border-color: rgba(64, 158, 255, 0.5);
|
||||||
|
color: white;
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
.email-input :deep(.el-input__wrapper) {
|
.email-input :deep(.el-input__wrapper) {
|
||||||
background: rgba(0, 0, 0, 0.3);
|
background: rgba(0, 0, 0, 0.3);
|
||||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
|||||||
@@ -130,7 +130,25 @@
|
|||||||
<el-col v-for="item in filteredItems" :key="item.id" :xs="24" :sm="12" :md="8" :lg="6">
|
<el-col v-for="item in filteredItems" :key="item.id" :xs="24" :sm="12" :md="8" :lg="6">
|
||||||
<el-card class="work-card" :class="{ selected: selectedIds.has(item.id) }" shadow="hover">
|
<el-card class="work-card" :class="{ selected: selectedIds.has(item.id) }" shadow="hover">
|
||||||
<div class="thumb" @click="multiSelect ? toggleSelect(item.id) : openDetail(item)">
|
<div class="thumb" @click="multiSelect ? toggleSelect(item.id) : openDetail(item)">
|
||||||
<img :src="item.cover" :alt="item.title" />
|
<!-- 如果是视频类型且有视频URL,使用video元素显示首帧 -->
|
||||||
|
<video
|
||||||
|
v-if="item.type === 'video' && item.resultUrl"
|
||||||
|
:src="item.resultUrl"
|
||||||
|
class="work-thumbnail-video"
|
||||||
|
muted
|
||||||
|
preload="metadata"
|
||||||
|
@loadedmetadata="onVideoLoaded"
|
||||||
|
></video>
|
||||||
|
<!-- 如果有封面图(thumbnailUrl),使用图片 -->
|
||||||
|
<img
|
||||||
|
v-else-if="item.cover && item.cover !== item.resultUrl"
|
||||||
|
:src="item.cover"
|
||||||
|
:alt="item.title"
|
||||||
|
/>
|
||||||
|
<!-- 否则使用默认占位符 -->
|
||||||
|
<div v-else class="work-placeholder">
|
||||||
|
<el-icon><VideoPlay /></el-icon>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="checker" v-if="multiSelect">
|
<div class="checker" v-if="multiSelect">
|
||||||
<el-checkbox :model-value="selectedIds.has(item.id)" @change="() => toggleSelect(item.id)" />
|
<el-checkbox :model-value="selectedIds.has(item.id)" @change="() => toggleSelect(item.id)" />
|
||||||
@@ -191,7 +209,7 @@
|
|||||||
<video
|
<video
|
||||||
v-if="selectedItem.type === 'video'"
|
v-if="selectedItem.type === 'video'"
|
||||||
class="detail-video"
|
class="detail-video"
|
||||||
:src="selectedItem.cover"
|
:src="selectedItem.resultUrl || selectedItem.cover"
|
||||||
:poster="selectedItem.cover"
|
:poster="selectedItem.cover"
|
||||||
controls
|
controls
|
||||||
>
|
>
|
||||||
@@ -314,7 +332,7 @@
|
|||||||
import { ref, onMounted, computed } from 'vue'
|
import { ref, onMounted, computed } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { Star, User, Compass, Document, VideoPlay, Picture, Film, Bell, Setting, Search } from '@element-plus/icons-vue'
|
import { Star, User, Compass, Document, VideoPlay, Picture, Film, Bell, Setting, Search, MoreFilled } from '@element-plus/icons-vue'
|
||||||
import { getMyWorks } from '@/api/userWorks'
|
import { getMyWorks } from '@/api/userWorks'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -341,6 +359,28 @@ const loading = ref(false)
|
|||||||
const hasMore = ref(true)
|
const hasMore = ref(true)
|
||||||
const items = ref([])
|
const items = ref([])
|
||||||
|
|
||||||
|
// 将后端返回的UserWork数据转换为前端需要的格式
|
||||||
|
const transformWorkData = (work) => {
|
||||||
|
return {
|
||||||
|
id: work.id?.toString() || work.taskId || '',
|
||||||
|
title: work.title || work.prompt || '未命名作品',
|
||||||
|
cover: work.thumbnailUrl || work.resultUrl || '/images/backgrounds/welcome.jpg',
|
||||||
|
resultUrl: work.resultUrl || '',
|
||||||
|
type: work.workType === 'TEXT_TO_VIDEO' || work.workType === 'IMAGE_TO_VIDEO' ? 'video' : 'image',
|
||||||
|
category: work.workType === 'TEXT_TO_VIDEO' ? '文生视频' : work.workType === 'IMAGE_TO_VIDEO' ? '图生视频' : '未知',
|
||||||
|
sizeText: work.fileSize || '未知大小',
|
||||||
|
createTime: work.createdAt ? new Date(work.createdAt).toLocaleString('zh-CN') : '',
|
||||||
|
date: work.createdAt ? new Date(work.createdAt).toLocaleDateString('zh-CN') : '',
|
||||||
|
description: work.description || work.prompt || '',
|
||||||
|
prompt: work.prompt || '',
|
||||||
|
duration: work.duration || '',
|
||||||
|
aspectRatio: work.aspectRatio || '',
|
||||||
|
quality: work.quality || '',
|
||||||
|
status: work.status || 'COMPLETED',
|
||||||
|
overlayText: work.prompt || ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const loadList = async () => {
|
const loadList = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
@@ -352,8 +392,11 @@ const loadList = async () => {
|
|||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
const data = response.data.data || []
|
const data = response.data.data || []
|
||||||
|
|
||||||
|
// 转换数据格式
|
||||||
|
const transformedData = data.map(transformWorkData)
|
||||||
|
|
||||||
if (page.value === 1) items.value = []
|
if (page.value === 1) items.value = []
|
||||||
items.value = items.value.concat(data)
|
items.value = items.value.concat(transformedData)
|
||||||
hasMore.value = data.length === pageSize.value
|
hasMore.value = data.length === pageSize.value
|
||||||
} else {
|
} else {
|
||||||
throw new Error(response.data.message || '获取作品列表失败')
|
throw new Error(response.data.message || '获取作品列表失败')
|
||||||
@@ -545,6 +588,17 @@ const resetFilters = () => {
|
|||||||
ElMessage.success('筛选器已重置')
|
ElMessage.success('筛选器已重置')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 视频加载元数据后,跳转到第一帧(但不播放)
|
||||||
|
const onVideoLoaded = (event) => {
|
||||||
|
const video = event.target
|
||||||
|
if (video && video.duration) {
|
||||||
|
// 跳转到第一帧(0秒)
|
||||||
|
video.currentTime = 0.1
|
||||||
|
// 确保视频不播放
|
||||||
|
video.pause()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadList()
|
loadList()
|
||||||
})
|
})
|
||||||
@@ -799,6 +853,28 @@ onMounted(() => {
|
|||||||
.work-card { margin-bottom: 14px; }
|
.work-card { margin-bottom: 14px; }
|
||||||
.thumb { position: relative; width: 100%; padding-top: 56.25%; overflow: hidden; border-radius: 6px; cursor: pointer; }
|
.thumb { position: relative; width: 100%; padding-top: 56.25%; overflow: hidden; border-radius: 6px; cursor: pointer; }
|
||||||
.thumb img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
|
.thumb img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
|
||||||
|
.work-thumbnail-video {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.work-placeholder {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: rgba(0, 0, 0, 0.3);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: #999;
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
.checker { position: absolute; left: 6px; top: 6px; }
|
.checker { position: absolute; left: 6px; top: 6px; }
|
||||||
.actions { position: absolute; right: 6px; top: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .2s ease; }
|
.actions { position: absolute; right: 6px; top: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .2s ease; }
|
||||||
.thumb:hover .actions { opacity: 1; }
|
.thumb:hover .actions { opacity: 1; }
|
||||||
|
|||||||
@@ -81,18 +81,38 @@
|
|||||||
<section class="published-section">
|
<section class="published-section">
|
||||||
<h3 class="section-title">已发布</h3>
|
<h3 class="section-title">已发布</h3>
|
||||||
<div class="video-grid">
|
<div class="video-grid">
|
||||||
<div class="video-item" v-for="(video, index) in videos" :key="index">
|
<div class="video-item" v-for="(video, index) in videos" :key="video.id || index" v-loading="loading">
|
||||||
<div class="video-thumbnail">
|
<div class="video-thumbnail" @click="goToCreate(video)">
|
||||||
<div class="thumbnail-image">
|
<div class="thumbnail-image">
|
||||||
<div class="figure"></div>
|
<!-- 如果是视频类型且有视频URL,使用video元素显示首帧 -->
|
||||||
<div class="text-overlay">What Does it Mean To You</div>
|
<video
|
||||||
|
v-if="video.type === 'video' && video.resultUrl"
|
||||||
|
:src="video.resultUrl"
|
||||||
|
class="video-cover-img"
|
||||||
|
muted
|
||||||
|
preload="metadata"
|
||||||
|
@loadedmetadata="onVideoLoaded"
|
||||||
|
></video>
|
||||||
|
<!-- 如果有封面图(thumbnailUrl),使用图片 -->
|
||||||
|
<img
|
||||||
|
v-else-if="video.cover && video.cover !== video.resultUrl"
|
||||||
|
:src="video.cover"
|
||||||
|
:alt="video.title"
|
||||||
|
class="video-cover-img"
|
||||||
|
/>
|
||||||
|
<!-- 否则使用占位符 -->
|
||||||
|
<div v-else class="figure"></div>
|
||||||
|
<div class="text-overlay" v-if="video.text">{{ video.text }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="video-action">
|
<div class="video-action">
|
||||||
<el-button v-if="index === 0" type="primary" size="small">做同款</el-button>
|
<el-button v-if="index === 0" type="primary" size="small" @click.stop="goToCreate(video)">做同款</el-button>
|
||||||
<span v-else class="director-text">DIRECTED BY VANNOCENT</span>
|
<span v-else class="director-text">DIRECTED BY VANNOCENT</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="!loading && videos.length === 0" class="empty-works">
|
||||||
|
<div class="empty-text">暂无作品,开始创作吧!</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
@@ -145,6 +165,7 @@ import {
|
|||||||
Picture,
|
Picture,
|
||||||
Film
|
Film
|
||||||
} from '@element-plus/icons-vue'
|
} from '@element-plus/icons-vue'
|
||||||
|
import { getMyWorks } from '@/api/userWorks'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
@@ -154,7 +175,8 @@ const showUserMenu = ref(false)
|
|||||||
const userStatusRef = ref(null)
|
const userStatusRef = ref(null)
|
||||||
|
|
||||||
// 视频数据
|
// 视频数据
|
||||||
const videos = ref(Array(6).fill({}))
|
const videos = ref([])
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
// 计算菜单位置
|
// 计算菜单位置
|
||||||
const menuStyle = computed(() => {
|
const menuStyle = computed(() => {
|
||||||
@@ -251,6 +273,44 @@ const logout = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将后端返回的UserWork数据转换为前端需要的格式
|
||||||
|
const transformWorkData = (work) => {
|
||||||
|
return {
|
||||||
|
id: work.id?.toString() || work.taskId || '',
|
||||||
|
title: work.title || work.prompt || '未命名作品',
|
||||||
|
cover: work.thumbnailUrl || work.resultUrl || '/images/backgrounds/welcome.jpg',
|
||||||
|
resultUrl: work.resultUrl || '',
|
||||||
|
type: work.workType === 'TEXT_TO_VIDEO' || work.workType === 'IMAGE_TO_VIDEO' ? 'video' : 'image',
|
||||||
|
text: work.prompt || '',
|
||||||
|
category: work.workType === 'TEXT_TO_VIDEO' ? '文生视频' : work.workType === 'IMAGE_TO_VIDEO' ? '图生视频' : '未知',
|
||||||
|
size: work.fileSize || '未知大小',
|
||||||
|
createTime: work.createdAt ? new Date(work.createdAt).toLocaleString('zh-CN') : ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载用户作品列表
|
||||||
|
const loadVideos = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const response = await getMyWorks({
|
||||||
|
page: 0,
|
||||||
|
size: 6 // 只加载前6个作品
|
||||||
|
})
|
||||||
|
|
||||||
|
if (response.data.success) {
|
||||||
|
const data = response.data.data || []
|
||||||
|
// 转换数据格式
|
||||||
|
videos.value = data.map(transformWorkData)
|
||||||
|
} else {
|
||||||
|
console.error('获取作品列表失败:', response.data.message)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载作品列表失败:', error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 点击外部关闭菜单
|
// 点击外部关闭菜单
|
||||||
const handleClickOutside = (event) => {
|
const handleClickOutside = (event) => {
|
||||||
const userStatus = event.target.closest('.user-status')
|
const userStatus = event.target.closest('.user-status')
|
||||||
@@ -259,8 +319,31 @@ const handleClickOutside = (event) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 跳转到作品详情或创作页面
|
||||||
|
const goToCreate = (video) => {
|
||||||
|
if (video && video.category === '文生视频') {
|
||||||
|
router.push('/text-to-video/create')
|
||||||
|
} else if (video && video.category === '图生视频') {
|
||||||
|
router.push('/image-to-video/create')
|
||||||
|
} else {
|
||||||
|
router.push('/text-to-video/create')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 视频加载元数据后,跳转到第一帧(但不播放)
|
||||||
|
const onVideoLoaded = (event) => {
|
||||||
|
const video = event.target
|
||||||
|
if (video && video.duration) {
|
||||||
|
// 跳转到第一帧(0秒)
|
||||||
|
video.currentTime = 0.1
|
||||||
|
// 确保视频不播放
|
||||||
|
video.pause()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
document.addEventListener('click', handleClickOutside)
|
document.addEventListener('click', handleClickOutside)
|
||||||
|
loadVideos()
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
@@ -651,6 +734,20 @@ onUnmounted(() => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-cover-img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-cover-img video {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
.figure {
|
.figure {
|
||||||
@@ -673,6 +770,17 @@ onUnmounted(() => {
|
|||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.empty-works {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
text-align: center;
|
||||||
|
padding: 40px;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-text {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
.text-overlay {
|
.text-overlay {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 20px;
|
top: 20px;
|
||||||
|
|||||||
@@ -62,8 +62,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-meta">
|
<div class="user-meta">
|
||||||
<div class="username">mingzi_FBx7foZYDS7inLQb</div>
|
<div class="username">{{ userInfo.username || '加载中...' }}</div>
|
||||||
<div class="user-id">ID 2994509784706419</div>
|
<div class="user-id">ID {{ userInfo.userId || '...' }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="user-right">
|
<div class="user-right">
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
<div class="star-icon">
|
<div class="star-icon">
|
||||||
<el-icon><Star /></el-icon>
|
<el-icon><Star /></el-icon>
|
||||||
</div>
|
</div>
|
||||||
<span>50</span>
|
<span>{{ userInfo.points || 0 }}</span>
|
||||||
</div>
|
</div>
|
||||||
<button class="mini-btn" @click="goToOrderDetails">积分详情</button>
|
<button class="mini-btn" @click="goToOrderDetails">积分详情</button>
|
||||||
<button class="mini-btn" @click="goToWorks">我的订单</button>
|
<button class="mini-btn" @click="goToWorks">我的订单</button>
|
||||||
@@ -81,12 +81,12 @@
|
|||||||
<div class="row-bottom">
|
<div class="row-bottom">
|
||||||
<div class="summary-item">
|
<div class="summary-item">
|
||||||
<div class="summary-label">当前生效权益</div>
|
<div class="summary-label">当前生效权益</div>
|
||||||
<div class="summary-value">免费版</div>
|
<div class="summary-value">{{ subscriptionInfo.currentPlan || '免费版' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="divider-v"></div>
|
<div class="divider-v"></div>
|
||||||
<div class="summary-item">
|
<div class="summary-item">
|
||||||
<div class="summary-label">到期时间</div>
|
<div class="summary-label">到期时间</div>
|
||||||
<div class="summary-value">永久</div>
|
<div class="summary-value">{{ subscriptionInfo.expiryTime || '永久' }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="divider-v"></div>
|
<div class="divider-v"></div>
|
||||||
<div class="summary-item">
|
<div class="summary-item">
|
||||||
@@ -95,7 +95,7 @@
|
|||||||
<div class="star-icon">
|
<div class="star-icon">
|
||||||
<el-icon><Star /></el-icon>
|
<el-icon><Star /></el-icon>
|
||||||
</div>
|
</div>
|
||||||
<span class="points-number">50</span>
|
<span class="points-number">{{ userInfo.points || 0 }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -239,12 +239,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
import MyWorks from '@/views/MyWorks.vue'
|
import MyWorks from '@/views/MyWorks.vue'
|
||||||
import PaymentModal from '@/components/PaymentModal.vue'
|
import PaymentModal from '@/components/PaymentModal.vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { createPayment, createAlipayPayment } from '@/api/payments'
|
import { createPayment, createAlipayPayment, getUserSubscriptionInfo } from '@/api/payments'
|
||||||
|
import { useUserStore } from '@/stores/user'
|
||||||
import {
|
import {
|
||||||
User,
|
User,
|
||||||
Document,
|
Document,
|
||||||
@@ -259,6 +260,160 @@ import {
|
|||||||
} from '@element-plus/icons-vue'
|
} from '@element-plus/icons-vue'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
|
// 用户信息和订阅信息
|
||||||
|
const userInfo = ref({
|
||||||
|
username: '',
|
||||||
|
userId: null,
|
||||||
|
points: 0,
|
||||||
|
email: '',
|
||||||
|
nickname: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
const subscriptionInfo = ref({
|
||||||
|
currentPlan: '免费版',
|
||||||
|
expiryTime: '永久',
|
||||||
|
paidAt: null
|
||||||
|
})
|
||||||
|
|
||||||
|
// 加载用户订阅信息
|
||||||
|
const loadUserSubscriptionInfo = async () => {
|
||||||
|
try {
|
||||||
|
// 确保用户store已初始化
|
||||||
|
if (!userStore.initialized) {
|
||||||
|
await userStore.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查用户是否已认证
|
||||||
|
if (!userStore.isAuthenticated) {
|
||||||
|
console.warn('用户未认证,跳转到登录页')
|
||||||
|
ElMessage.warning('请先登录')
|
||||||
|
router.push('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查token是否存在
|
||||||
|
const token = userStore.token || sessionStorage.getItem('token')
|
||||||
|
if (!token || token === 'null' || token.trim() === '') {
|
||||||
|
console.warn('未找到有效的token,跳转到登录页')
|
||||||
|
ElMessage.warning('请先登录')
|
||||||
|
router.push('/login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('开始加载用户订阅信息...')
|
||||||
|
const response = await getUserSubscriptionInfo()
|
||||||
|
console.log('用户订阅信息响应完整对象:', response)
|
||||||
|
console.log('响应状态码:', response.status)
|
||||||
|
console.log('响应数据:', response.data)
|
||||||
|
console.log('响应数据类型:', typeof response.data)
|
||||||
|
|
||||||
|
// 检查是否是HTML响应(302重定向的结果)
|
||||||
|
if (typeof response.data === 'string' && response.data.includes('<!DOCTYPE html>')) {
|
||||||
|
console.error('收到HTML响应,可能是认证失败导致重定向到登录页')
|
||||||
|
// 响应拦截器已经处理了跳转和清除token,这里直接返回
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查响应结构
|
||||||
|
if (response.data) {
|
||||||
|
// 如果response.data.success存在且为true
|
||||||
|
if (response.data.success === true && response.data.data) {
|
||||||
|
const data = response.data.data
|
||||||
|
userInfo.value = {
|
||||||
|
username: data.username || '',
|
||||||
|
userId: data.userId || null,
|
||||||
|
points: data.points || 0,
|
||||||
|
email: data.email || '',
|
||||||
|
nickname: data.nickname || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
subscriptionInfo.value = {
|
||||||
|
currentPlan: data.currentPlan || '免费版',
|
||||||
|
expiryTime: data.expiryTime || '永久',
|
||||||
|
paidAt: data.paidAt || null
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('用户信息加载成功:', userInfo.value)
|
||||||
|
console.log('订阅信息加载成功:', subscriptionInfo.value)
|
||||||
|
} else {
|
||||||
|
// 如果响应结构不同,尝试直接使用response.data
|
||||||
|
console.warn('响应格式不符合预期,尝试直接使用response.data')
|
||||||
|
const data = response.data.data || response.data
|
||||||
|
if (data && typeof data === 'object' && (data.username || data.userId)) {
|
||||||
|
userInfo.value = {
|
||||||
|
username: data.username || '',
|
||||||
|
userId: data.userId || null,
|
||||||
|
points: data.points || 0,
|
||||||
|
email: data.email || '',
|
||||||
|
nickname: data.nickname || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
subscriptionInfo.value = {
|
||||||
|
currentPlan: data.currentPlan || '免费版',
|
||||||
|
expiryTime: data.expiryTime || '永久',
|
||||||
|
paidAt: data.paidAt || null
|
||||||
|
}
|
||||||
|
console.log('用户信息加载成功(备用路径):', userInfo.value)
|
||||||
|
} else {
|
||||||
|
console.error('获取用户订阅信息失败: 响应数据为空或格式不正确')
|
||||||
|
console.error('完整响应:', JSON.stringify(response.data, null, 2))
|
||||||
|
ElMessage.warning('获取用户信息失败,使用默认值')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error('获取用户订阅信息失败: response.data为空')
|
||||||
|
console.error('完整响应对象:', response)
|
||||||
|
ElMessage.warning('获取用户信息失败,使用默认值')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载用户订阅信息失败:', error)
|
||||||
|
console.error('错误详情:', error.response?.data || error.message)
|
||||||
|
|
||||||
|
// 如果是认证失败(401、403、302或HTML响应),响应拦截器已经处理了跳转
|
||||||
|
if (error.response?.status === 401 ||
|
||||||
|
error.response?.status === 403 ||
|
||||||
|
error.response?.status === 302 ||
|
||||||
|
error.message?.includes('认证失败') ||
|
||||||
|
error.message?.includes('redirect')) {
|
||||||
|
// 响应拦截器已经处理了跳转,这里不再重复处理
|
||||||
|
console.warn('认证失败,响应拦截器已处理跳转')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其他错误才显示消息
|
||||||
|
ElMessage.error('加载用户信息失败: ' + (error.response?.data?.message || error.message || '请刷新页面重试'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组件挂载时加载数据
|
||||||
|
onMounted(async () => {
|
||||||
|
// 确保用户store已初始化
|
||||||
|
if (!userStore.initialized) {
|
||||||
|
await userStore.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果用户已登录,加载订阅信息
|
||||||
|
if (userStore.isAuthenticated) {
|
||||||
|
// 先从store中获取基本信息(如果可用)
|
||||||
|
if (userStore.user) {
|
||||||
|
userInfo.value = {
|
||||||
|
username: userStore.user.username || '',
|
||||||
|
userId: userStore.user.id || null,
|
||||||
|
points: userStore.user.points || 0,
|
||||||
|
email: userStore.user.email || '',
|
||||||
|
nickname: userStore.user.nickname || ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 然后从API获取完整的订阅信息
|
||||||
|
await loadUserSubscriptionInfo()
|
||||||
|
} else {
|
||||||
|
// 路由守卫应该已经处理了跳转,但这里作为双重保险
|
||||||
|
console.warn('用户未登录,路由守卫应该已处理跳转')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// 跳转到个人主页
|
// 跳转到个人主页
|
||||||
const goToProfile = () => {
|
const goToProfile = () => {
|
||||||
@@ -406,23 +561,36 @@ const generateQRCode = async (planType, planInfo) => {
|
|||||||
console.log('4. 支付宝二维码:', qrCode)
|
console.log('4. 支付宝二维码:', qrCode)
|
||||||
|
|
||||||
if (qrCode) {
|
if (qrCode) {
|
||||||
// 更新二维码显示
|
// 使用在线API生成二维码图片(直接使用支付宝返回的URL生成二维码)
|
||||||
const qrCodeElement = document.querySelector('#qr-code-img')
|
try {
|
||||||
if (qrCodeElement) {
|
console.log('开始生成二维码,内容:', qrCode)
|
||||||
qrCodeElement.src = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(qrCode)}`
|
|
||||||
qrCodeElement.style.display = 'block'
|
// 使用QuickChart API生成二维码,完全去除白边
|
||||||
console.log('5. 二维码图片已设置')
|
const qrCodeUrl = `https://quickchart.io/qr?text=${encodeURIComponent(qrCode)}&size=200&margin=0&dark=ffffff&light=1a1a1a`
|
||||||
|
|
||||||
|
console.log('5. 二维码图片URL已生成')
|
||||||
|
|
||||||
|
// 更新二维码显示
|
||||||
|
const qrCodeElement = document.querySelector('#qr-code-img')
|
||||||
|
if (qrCodeElement) {
|
||||||
|
qrCodeElement.src = qrCodeUrl
|
||||||
|
qrCodeElement.style.display = 'block'
|
||||||
|
console.log('6. 二维码图片已设置')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 隐藏模拟二维码
|
||||||
|
const qrPlaceholder = document.querySelector('.qr-placeholder')
|
||||||
|
if (qrPlaceholder) {
|
||||||
|
qrPlaceholder.style.display = 'none'
|
||||||
|
console.log('7. 模拟二维码已隐藏')
|
||||||
|
}
|
||||||
|
|
||||||
|
ElMessage.success('二维码已生成,请使用支付宝扫码支付')
|
||||||
|
console.log('=== 二维码生成完成 ===')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('生成二维码失败:', error)
|
||||||
|
ElMessage.error('生成二维码失败,请重试')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏模拟二维码
|
|
||||||
const qrPlaceholder = document.querySelector('.qr-placeholder')
|
|
||||||
if (qrPlaceholder) {
|
|
||||||
qrPlaceholder.style.display = 'none'
|
|
||||||
console.log('6. 模拟二维码已隐藏')
|
|
||||||
}
|
|
||||||
|
|
||||||
ElMessage.success('二维码已生成,请使用支付宝扫码支付')
|
|
||||||
console.log('=== 二维码生成完成 ===')
|
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error('二维码生成失败:二维码为空')
|
ElMessage.error('二维码生成失败:二维码为空')
|
||||||
}
|
}
|
||||||
@@ -464,21 +632,19 @@ const getPlanInfo = (planType) => {
|
|||||||
// 支付成功处理
|
// 支付成功处理
|
||||||
const handlePaymentSuccess = async (paymentData) => {
|
const handlePaymentSuccess = async (paymentData) => {
|
||||||
try {
|
try {
|
||||||
ElMessage.success('支付成功!正在处理订单...')
|
console.log('✅ 收到支付成功事件,支付数据:', paymentData)
|
||||||
|
ElMessage.success('支付成功!正在更新信息...')
|
||||||
// 这里可以添加支付成功后的处理逻辑
|
|
||||||
// 比如更新用户状态、发送确认邮件等
|
|
||||||
|
|
||||||
// 关闭支付模态框
|
// 关闭支付模态框
|
||||||
paymentModalVisible.value = false
|
paymentModalVisible.value = false
|
||||||
|
|
||||||
// 刷新页面或更新用户信息
|
// 重新加载用户订阅信息
|
||||||
setTimeout(() => {
|
await loadUserSubscriptionInfo()
|
||||||
window.location.reload()
|
|
||||||
}, 2000)
|
ElMessage.success('信息已更新!')
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('支付成功处理失败:', error)
|
console.error('❌ 支付成功处理失败:', error)
|
||||||
ElMessage.error('支付成功但处理订单失败,请联系客服')
|
ElMessage.error('支付成功但处理订单失败,请联系客服')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -394,6 +394,11 @@ const startPollingTask = () => {
|
|||||||
if (progressData && progressData.status) {
|
if (progressData && progressData.status) {
|
||||||
taskStatus.value = progressData.status
|
taskStatus.value = progressData.status
|
||||||
}
|
}
|
||||||
|
// 更新resultUrl(如果存在)
|
||||||
|
if (progressData && progressData.resultUrl && currentTask.value) {
|
||||||
|
currentTask.value.resultUrl = progressData.resultUrl
|
||||||
|
console.log('更新resultUrl:', progressData.resultUrl)
|
||||||
|
}
|
||||||
console.log('任务进度:', progressData)
|
console.log('任务进度:', progressData)
|
||||||
},
|
},
|
||||||
// 完成回调
|
// 完成回调
|
||||||
@@ -401,6 +406,11 @@ const startPollingTask = () => {
|
|||||||
inProgress.value = false
|
inProgress.value = false
|
||||||
taskProgress.value = 100
|
taskProgress.value = 100
|
||||||
taskStatus.value = 'COMPLETED'
|
taskStatus.value = 'COMPLETED'
|
||||||
|
// 更新currentTask的resultUrl
|
||||||
|
if (taskData && taskData.resultUrl && currentTask.value) {
|
||||||
|
currentTask.value.resultUrl = taskData.resultUrl
|
||||||
|
console.log('任务完成,resultUrl已更新:', taskData.resultUrl)
|
||||||
|
}
|
||||||
ElMessage.success('视频生成完成!')
|
ElMessage.success('视频生成完成!')
|
||||||
|
|
||||||
// 可以在这里跳转到结果页面或显示结果
|
// 可以在这里跳转到结果页面或显示结果
|
||||||
|
|||||||
29
demo/frpc.ini.example
Normal file
29
demo/frpc.ini.example
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# FRP 客户端配置文件示例
|
||||||
|
# 使用 OpenFrp 或其他免费 FRP 服务时使用此配置
|
||||||
|
|
||||||
|
[common]
|
||||||
|
# 服务器地址(从 FRP 服务提供商控制台获取)
|
||||||
|
server_addr = frp.example.com
|
||||||
|
# 服务器端口(通常是 7000)
|
||||||
|
server_port = 7000
|
||||||
|
# 认证 token(从 FRP 服务提供商控制台获取)
|
||||||
|
token = your_token_here
|
||||||
|
|
||||||
|
[payment]
|
||||||
|
# 隧道类型:http
|
||||||
|
type = http
|
||||||
|
# 本地 IP(通常是 127.0.0.1)
|
||||||
|
local_ip = 127.0.0.1
|
||||||
|
# 本地端口(Spring Boot 运行端口)
|
||||||
|
local_port = 8080
|
||||||
|
# 自定义域名(从 FRP 服务提供商控制台获取)
|
||||||
|
custom_domains = your-domain.openfrp.net
|
||||||
|
|
||||||
|
# 如果需要多个服务,可以添加更多配置段
|
||||||
|
# [other-service]
|
||||||
|
# type = http
|
||||||
|
# local_ip = 127.0.0.1
|
||||||
|
# local_port = 3000
|
||||||
|
# custom_domains = other-domain.openfrp.net
|
||||||
|
|
||||||
|
|
||||||
@@ -22,7 +22,6 @@ import com.example.demo.util.JwtUtils;
|
|||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/auth")
|
@RequestMapping("/api/auth")
|
||||||
@@ -82,47 +81,84 @@ public class AuthApiController {
|
|||||||
if (user == null) {
|
if (user == null) {
|
||||||
// 自动注册新用户
|
// 自动注册新用户
|
||||||
try {
|
try {
|
||||||
|
logger.info("邮箱验证码登录 - 用户不存在,开始自动注册:{}", email);
|
||||||
|
|
||||||
// 从邮箱生成用户名(去掉@符号及后面的部分)
|
// 从邮箱生成用户名(去掉@符号及后面的部分)
|
||||||
String username = email.split("@")[0];
|
String username = email.split("@")[0];
|
||||||
logger.info("邮箱验证码登录 - 原始邮箱: '{}', 生成的用户名: '{}'", email, username);
|
logger.info("邮箱验证码登录 - 原始邮箱: '{}', 生成的用户名: '{}'", email, username);
|
||||||
|
|
||||||
|
// 清理用户名(移除特殊字符,只保留字母、数字、下划线)
|
||||||
|
username = username.replaceAll("[^a-zA-Z0-9_]", "_");
|
||||||
|
|
||||||
// 确保用户名长度不超过50个字符
|
// 确保用户名长度不超过50个字符
|
||||||
if (username.length() > 50) {
|
if (username.length() > 50) {
|
||||||
username = username.substring(0, 50);
|
username = username.substring(0, 50);
|
||||||
logger.info("邮箱验证码登录 - 用户名过长,截断为: '{}'", username);
|
logger.info("邮箱验证码登录 - 用户名过长,截断为: '{}'", username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 确保用户名不为空且至少3个字符
|
||||||
|
if (username.length() < 3) {
|
||||||
|
username = username + "_" + System.currentTimeMillis() % 1000;
|
||||||
|
if (username.length() > 50) {
|
||||||
|
username = username.substring(0, 50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 确保用户名唯一
|
// 确保用户名唯一
|
||||||
String originalUsername = username;
|
String originalUsername = username;
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
while (userService.findByUsernameOrNull(username) != null) {
|
while (userService.findByUsernameOrNull(username) != null) {
|
||||||
// 如果用户名过长,需要重新截断
|
// 如果用户名过长,需要重新截断
|
||||||
String newUsername = originalUsername + counter;
|
String baseUsername = originalUsername.length() > 45 ?
|
||||||
|
originalUsername.substring(0, 45) : originalUsername;
|
||||||
|
String newUsername = baseUsername + counter;
|
||||||
if (newUsername.length() > 50) {
|
if (newUsername.length() > 50) {
|
||||||
newUsername = newUsername.substring(0, 50);
|
newUsername = newUsername.substring(0, 50);
|
||||||
}
|
}
|
||||||
username = newUsername;
|
username = newUsername;
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
|
// 防止无限循环
|
||||||
|
if (counter > 1000) {
|
||||||
|
// 使用时间戳确保唯一性
|
||||||
|
username = "user_" + System.currentTimeMillis();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建新用户
|
logger.info("邮箱验证码登录 - 最终用户名: '{}'", username);
|
||||||
|
|
||||||
|
// 直接创建用户对象并设置所有必要字段
|
||||||
user = new User();
|
user = new User();
|
||||||
user.setUsername(username);
|
user.setUsername(username);
|
||||||
user.setEmail(email);
|
user.setEmail(email);
|
||||||
user.setPasswordHash(""); // 邮箱登录不需要密码
|
user.setPasswordHash(""); // 邮箱登录不需要密码
|
||||||
user.setRole("ROLE_USER"); // 默认为普通用户
|
user.setRole("ROLE_USER"); // 默认为普通用户
|
||||||
user.setPoints(50); // 默认积分
|
user.setPoints(50); // 默认50积分
|
||||||
|
user.setFrozenPoints(0); // 默认冻结积分为0
|
||||||
user.setNickname(username); // 默认昵称为用户名
|
user.setNickname(username); // 默认昵称为用户名
|
||||||
user.setIsActive(true);
|
user.setIsActive(true);
|
||||||
|
|
||||||
// 保存用户
|
// 保存用户(@PrePersist 会自动设置 createdAt 等字段)
|
||||||
user = userService.save(user);
|
user = userService.save(user);
|
||||||
|
|
||||||
logger.info("自动注册新用户:{}", email);
|
logger.info("✅ 用户已保存到数据库 - ID: {}, 用户名: {}, 邮箱: {}",
|
||||||
|
user.getId(), user.getUsername(), user.getEmail());
|
||||||
|
|
||||||
|
logger.info("✅ 自动注册新用户成功 - 邮箱: {}, 用户名: {}, ID: {}",
|
||||||
|
email, username, user.getId());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.error("❌ 自动注册用户失败(参数错误):{} - {}", email, e.getMessage());
|
||||||
|
return ResponseEntity.badRequest()
|
||||||
|
.body(createErrorResponse("用户注册失败:" + e.getMessage()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("自动注册用户失败:{}", email, e);
|
logger.error("❌ 自动注册用户失败:{}", email, e);
|
||||||
return ResponseEntity.badRequest()
|
return ResponseEntity.badRequest()
|
||||||
.body(createErrorResponse("用户注册失败:" + e.getMessage()));
|
.body(createErrorResponse("用户注册失败:" + e.getMessage()));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logger.info("✅ 找到现有用户 - 邮箱: {}, 用户名: {}, ID: {}",
|
||||||
|
email, user.getUsername(), user.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成JWT Token
|
// 生成JWT Token
|
||||||
@@ -153,28 +189,59 @@ public class AuthApiController {
|
|||||||
* 用户注册
|
* 用户注册
|
||||||
*/
|
*/
|
||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
public ResponseEntity<Map<String, Object>> register(@Valid @RequestBody User user) {
|
public ResponseEntity<Map<String, Object>> register(@RequestBody Map<String, String> requestData) {
|
||||||
try {
|
try {
|
||||||
if (userService.findByUsername(user.getUsername()) != null) {
|
String username = requestData.get("username");
|
||||||
|
String email = requestData.get("email");
|
||||||
|
String password = requestData.get("password");
|
||||||
|
|
||||||
|
// 验证必填字段
|
||||||
|
if (username == null || username.trim().isEmpty()) {
|
||||||
|
return ResponseEntity.badRequest()
|
||||||
|
.body(createErrorResponse("用户名不能为空"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (email == null || email.trim().isEmpty()) {
|
||||||
|
return ResponseEntity.badRequest()
|
||||||
|
.body(createErrorResponse("邮箱不能为空"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password == null || password.trim().isEmpty()) {
|
||||||
|
return ResponseEntity.badRequest()
|
||||||
|
.body(createErrorResponse("密码不能为空"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查用户名是否已存在
|
||||||
|
User existingUser = userService.findByUsernameOrNull(username);
|
||||||
|
if (existingUser != null) {
|
||||||
return ResponseEntity.badRequest()
|
return ResponseEntity.badRequest()
|
||||||
.body(createErrorResponse("用户名已存在"));
|
.body(createErrorResponse("用户名已存在"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userService.findByEmail(user.getEmail()) != null) {
|
// 检查邮箱是否已存在
|
||||||
|
User existingEmail = userService.findByEmailOrNull(email);
|
||||||
|
if (existingEmail != null) {
|
||||||
return ResponseEntity.badRequest()
|
return ResponseEntity.badRequest()
|
||||||
.body(createErrorResponse("邮箱已存在"));
|
.body(createErrorResponse("邮箱已存在"));
|
||||||
}
|
}
|
||||||
|
|
||||||
User savedUser = userService.save(user);
|
// 使用 register 方法创建用户(会自动编码密码)
|
||||||
|
User savedUser = userService.register(username, email, password);
|
||||||
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
Map<String, Object> response = new HashMap<>();
|
||||||
response.put("success", true);
|
response.put("success", true);
|
||||||
response.put("message", "注册成功");
|
response.put("message", "注册成功");
|
||||||
|
// 不返回密码哈希
|
||||||
|
savedUser.setPasswordHash(null);
|
||||||
response.put("data", savedUser);
|
response.put("data", savedUser);
|
||||||
|
|
||||||
logger.info("用户注册成功:{}", user.getUsername());
|
logger.info("用户注册成功:{}", username);
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.warn("注册失败:{}", e.getMessage());
|
||||||
|
return ResponseEntity.badRequest()
|
||||||
|
.body(createErrorResponse(e.getMessage()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("注册失败:", e);
|
logger.error("注册失败:", e);
|
||||||
return ResponseEntity.badRequest()
|
return ResponseEntity.badRequest()
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.example.demo.controller;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||||
|
|
||||||
|
@ExceptionHandler(Exception.class)
|
||||||
|
public ResponseEntity<Map<String, Object>> handleException(Exception e) {
|
||||||
|
logger.error("全局异常处理器捕获到异常", e);
|
||||||
|
logger.error("异常类型: {}", e.getClass().getName());
|
||||||
|
logger.error("异常消息: {}", e.getMessage());
|
||||||
|
if (e.getCause() != null) {
|
||||||
|
logger.error("异常原因: {}", e.getCause().getMessage());
|
||||||
|
}
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
Map<String, Object> errorResponse = new HashMap<>();
|
||||||
|
errorResponse.put("success", false);
|
||||||
|
errorResponse.put("message", "服务器内部错误: " + e.getMessage());
|
||||||
|
errorResponse.put("error", e.getClass().getSimpleName());
|
||||||
|
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.example.demo.controller;
|
package com.example.demo.controller;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -21,8 +23,11 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import com.example.demo.model.Payment;
|
import com.example.demo.model.Payment;
|
||||||
import com.example.demo.model.PaymentStatus;
|
import com.example.demo.model.PaymentStatus;
|
||||||
|
import com.example.demo.model.User;
|
||||||
|
import com.example.demo.repository.PaymentRepository;
|
||||||
import com.example.demo.service.AlipayService;
|
import com.example.demo.service.AlipayService;
|
||||||
import com.example.demo.service.PaymentService;
|
import com.example.demo.service.PaymentService;
|
||||||
|
import com.example.demo.service.UserService;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/payments")
|
@RequestMapping("/api/payments")
|
||||||
@@ -35,6 +40,12 @@ public class PaymentApiController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AlipayService alipayService;
|
private AlipayService alipayService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PaymentRepository paymentRepository;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -361,6 +372,109 @@ public class PaymentApiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户订阅信息(当前套餐、到期时间等)
|
||||||
|
*/
|
||||||
|
@GetMapping("/subscription/info")
|
||||||
|
public ResponseEntity<Map<String, Object>> getUserSubscriptionInfo(
|
||||||
|
Authentication authentication) {
|
||||||
|
try {
|
||||||
|
logger.info("=== 开始获取用户订阅信息 ===");
|
||||||
|
|
||||||
|
if (authentication == null || !authentication.isAuthenticated()) {
|
||||||
|
logger.warn("用户未认证");
|
||||||
|
return ResponseEntity.badRequest()
|
||||||
|
.body(createErrorResponse("请先登录"));
|
||||||
|
}
|
||||||
|
|
||||||
|
String username = authentication.getName();
|
||||||
|
logger.info("认证用户名: {}", username);
|
||||||
|
|
||||||
|
User user = userService.findByUsername(username);
|
||||||
|
logger.info("查找用户结果: {}", user != null ? "找到用户,ID: " + user.getId() : "未找到用户");
|
||||||
|
|
||||||
|
if (user == null) {
|
||||||
|
logger.error("用户不存在: {}", username);
|
||||||
|
return ResponseEntity.badRequest()
|
||||||
|
.body(createErrorResponse("用户不存在"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取用户最近一次成功的订阅支付
|
||||||
|
logger.info("开始查询用户订阅记录,用户ID: {}", user.getId());
|
||||||
|
List<Payment> subscriptions;
|
||||||
|
try {
|
||||||
|
subscriptions = paymentRepository.findLatestSuccessfulSubscriptionByUserId(user.getId(), PaymentStatus.SUCCESS);
|
||||||
|
logger.info("用户 {} (ID: {}) 的订阅记录数量: {}", username, user.getId(), subscriptions.size());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("查询订阅记录失败,用户ID: {}", user.getId(), e);
|
||||||
|
// 如果查询失败,使用空列表
|
||||||
|
subscriptions = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> subscriptionInfo = new HashMap<>();
|
||||||
|
|
||||||
|
// 默认值:免费版
|
||||||
|
String currentPlan = "免费版";
|
||||||
|
String expiryTime = "永久";
|
||||||
|
LocalDateTime paidAt = null;
|
||||||
|
|
||||||
|
if (!subscriptions.isEmpty()) {
|
||||||
|
logger.info("找到订阅记录,第一条描述: {}", subscriptions.get(0).getDescription());
|
||||||
|
Payment latestSubscription = subscriptions.get(0);
|
||||||
|
String description = latestSubscription.getDescription();
|
||||||
|
paidAt = latestSubscription.getPaidAt() != null ?
|
||||||
|
latestSubscription.getPaidAt() : latestSubscription.getCreatedAt();
|
||||||
|
|
||||||
|
// 从描述中识别套餐类型
|
||||||
|
if (description != null) {
|
||||||
|
if (description.contains("标准版")) {
|
||||||
|
currentPlan = "标准版会员";
|
||||||
|
} else if (description.contains("专业版")) {
|
||||||
|
currentPlan = "专业版会员";
|
||||||
|
} else if (description.contains("会员")) {
|
||||||
|
currentPlan = "会员";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算到期时间(假设订阅有效期为30天)
|
||||||
|
if (paidAt != null) {
|
||||||
|
LocalDateTime expiryDateTime = paidAt.plusDays(30);
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
|
if (expiryDateTime.isAfter(now)) {
|
||||||
|
// 未过期,显示到期时间
|
||||||
|
expiryTime = expiryDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
|
||||||
|
} else {
|
||||||
|
// 已过期,显示已过期
|
||||||
|
expiryTime = "已过期";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
subscriptionInfo.put("currentPlan", currentPlan);
|
||||||
|
subscriptionInfo.put("expiryTime", expiryTime);
|
||||||
|
subscriptionInfo.put("paidAt", paidAt != null ? paidAt.toString() : null);
|
||||||
|
subscriptionInfo.put("points", user.getPoints());
|
||||||
|
subscriptionInfo.put("username", user.getUsername());
|
||||||
|
subscriptionInfo.put("userId", user.getId());
|
||||||
|
subscriptionInfo.put("email", user.getEmail());
|
||||||
|
subscriptionInfo.put("nickname", user.getNickname());
|
||||||
|
|
||||||
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
response.put("success", true);
|
||||||
|
response.put("data", subscriptionInfo);
|
||||||
|
|
||||||
|
logger.info("=== 用户订阅信息获取成功 ===");
|
||||||
|
return ResponseEntity.ok(response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("获取用户订阅信息失败", e);
|
||||||
|
logger.error("异常堆栈: ", e);
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseEntity.status(500)
|
||||||
|
.body(createErrorResponse("获取用户订阅信息失败: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建支付宝支付
|
* 创建支付宝支付
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -100,6 +100,10 @@ public class PaymentController {
|
|||||||
@PostMapping("/alipay/notify")
|
@PostMapping("/alipay/notify")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String alipayNotify(HttpServletRequest request) {
|
public String alipayNotify(HttpServletRequest request) {
|
||||||
|
logger.info("========== 收到支付宝回调请求 ==========");
|
||||||
|
logger.info("请求方法: {}", request.getMethod());
|
||||||
|
logger.info("请求URL: {}", request.getRequestURL());
|
||||||
|
logger.info("Content-Type: {}", request.getContentType());
|
||||||
try {
|
try {
|
||||||
// 支付宝异步通知参数获取
|
// 支付宝异步通知参数获取
|
||||||
// 注意:IJPay的AliPayApi.toMap()使用javax.servlet,但Spring Boot 3使用jakarta.servlet
|
// 注意:IJPay的AliPayApi.toMap()使用javax.servlet,但Spring Boot 3使用jakarta.servlet
|
||||||
@@ -151,11 +155,14 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("解析到的参数: {}", params);
|
||||||
boolean success = alipayService.handleNotify(params);
|
boolean success = alipayService.handleNotify(params);
|
||||||
|
logger.info("处理结果: {}", success ? "success" : "fail");
|
||||||
|
logger.info("========== 支付宝回调处理完成 ==========");
|
||||||
return success ? "success" : "fail";
|
return success ? "success" : "fail";
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("处理支付宝异步通知失败:", e);
|
logger.error("========== 处理支付宝异步通知失败 ==========", e);
|
||||||
return "fail";
|
return "fail";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,3 +69,6 @@ public class MailMessage {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class ImageToVideoTask {
|
|||||||
@Column(name = "progress")
|
@Column(name = "progress")
|
||||||
private Integer progress = 0;
|
private Integer progress = 0;
|
||||||
|
|
||||||
@Column(name = "result_url")
|
@Column(name = "result_url", columnDefinition = "TEXT")
|
||||||
private String resultUrl;
|
private String resultUrl;
|
||||||
|
|
||||||
@Column(name = "real_task_id")
|
@Column(name = "real_task_id")
|
||||||
|
|||||||
@@ -203,3 +203,6 @@ public class PointsFreezeRecord {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class StoryboardVideoTask {
|
|||||||
@Column(columnDefinition = "TEXT")
|
@Column(columnDefinition = "TEXT")
|
||||||
private String prompt; // 文本描述
|
private String prompt; // 文本描述
|
||||||
|
|
||||||
@Column(length = 500)
|
@Column(name = "image_url", columnDefinition = "TEXT")
|
||||||
private String imageUrl; // 上传的参考图片URL(可选)
|
private String imageUrl; // 上传的参考图片URL(可选)
|
||||||
|
|
||||||
@Column(nullable = false, length = 10)
|
@Column(nullable = false, length = 10)
|
||||||
@@ -47,7 +47,7 @@ public class StoryboardVideoTask {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private int progress; // 0-100
|
private int progress; // 0-100
|
||||||
|
|
||||||
@Column(length = 500)
|
@Column(name = "result_url", columnDefinition = "TEXT")
|
||||||
private String resultUrl; // 分镜图URL
|
private String resultUrl; // 分镜图URL
|
||||||
|
|
||||||
@Column(name = "real_task_id")
|
@Column(name = "real_task_id")
|
||||||
|
|||||||
@@ -271,3 +271,6 @@ public class TaskQueue {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -263,3 +263,6 @@ public class TaskStatus {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
package com.example.demo.model;
|
package com.example.demo.model;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文生视频任务实体
|
* 文生视频任务实体
|
||||||
*/
|
*/
|
||||||
@@ -39,7 +47,7 @@ public class TextToVideoTask {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private int progress; // 0-100
|
private int progress; // 0-100
|
||||||
|
|
||||||
@Column(length = 500)
|
@Column(name = "result_url", columnDefinition = "TEXT")
|
||||||
private String resultUrl;
|
private String resultUrl;
|
||||||
|
|
||||||
@Column(name = "real_task_id")
|
@Column(name = "real_task_id")
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class User {
|
|||||||
@Column(name = "phone", length = 20)
|
@Column(name = "phone", length = 20)
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
@Column(name = "avatar", length = 500)
|
@Column(name = "avatar", columnDefinition = "TEXT")
|
||||||
private String avatar;
|
private String avatar;
|
||||||
|
|
||||||
@Column(name = "nickname", length = 100)
|
@Column(name = "nickname", length = 100)
|
||||||
@@ -79,7 +79,24 @@ public class User {
|
|||||||
|
|
||||||
@PrePersist
|
@PrePersist
|
||||||
protected void onCreate() {
|
protected void onCreate() {
|
||||||
createdAt = LocalDateTime.now();
|
if (createdAt == null) {
|
||||||
|
createdAt = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
if (updatedAt == null) {
|
||||||
|
updatedAt = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
if (points == null) {
|
||||||
|
points = 50; // 默认50积分
|
||||||
|
}
|
||||||
|
if (frozenPoints == null) {
|
||||||
|
frozenPoints = 0; // 默认冻结积分为0
|
||||||
|
}
|
||||||
|
if (role == null || role.isEmpty()) {
|
||||||
|
role = "ROLE_USER"; // 默认角色
|
||||||
|
}
|
||||||
|
if (isActive == null) {
|
||||||
|
isActive = true; // 默认激活
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
package com.example.demo.model;
|
package com.example.demo.model;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户作品实体
|
* 用户作品实体
|
||||||
* 记录用户生成的视频作品
|
* 记录用户生成的视频作品
|
||||||
@@ -37,10 +45,10 @@ public class UserWork {
|
|||||||
@Column(name = "prompt", columnDefinition = "TEXT")
|
@Column(name = "prompt", columnDefinition = "TEXT")
|
||||||
private String prompt; // 生成提示词
|
private String prompt; // 生成提示词
|
||||||
|
|
||||||
@Column(name = "result_url", length = 500)
|
@Column(name = "result_url", columnDefinition = "TEXT")
|
||||||
private String resultUrl; // 结果视频URL
|
private String resultUrl; // 结果视频URL
|
||||||
|
|
||||||
@Column(name = "thumbnail_url", length = 500)
|
@Column(name = "thumbnail_url", columnDefinition = "TEXT")
|
||||||
private String thumbnailUrl; // 缩略图URL
|
private String thumbnailUrl; // 缩略图URL
|
||||||
|
|
||||||
@Column(name = "duration", length = 10)
|
@Column(name = "duration", length = 10)
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
package com.example.demo.repository;
|
package com.example.demo.repository;
|
||||||
|
|
||||||
import com.example.demo.model.Payment;
|
import java.util.List;
|
||||||
import com.example.demo.model.PaymentStatus;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import com.example.demo.model.Payment;
|
||||||
import java.util.Optional;
|
import com.example.demo.model.PaymentStatus;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
||||||
@@ -62,4 +63,13 @@ public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
|||||||
"FROM Payment p WHERE p.status = 'COMPLETED' AND YEAR(p.paidAt) = :year " +
|
"FROM Payment p WHERE p.status = 'COMPLETED' AND YEAR(p.paidAt) = :year " +
|
||||||
"GROUP BY MONTH(p.paidAt) ORDER BY MONTH(p.paidAt)")
|
"GROUP BY MONTH(p.paidAt) ORDER BY MONTH(p.paidAt)")
|
||||||
List<java.util.Map<String, Object>> findMonthlyRevenueByYear(@Param("year") int year);
|
List<java.util.Map<String, Object>> findMonthlyRevenueByYear(@Param("year") int year);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户最近一次成功的订阅支付(按支付时间倒序)
|
||||||
|
*/
|
||||||
|
@Query("SELECT p FROM Payment p WHERE p.user.id = :userId " +
|
||||||
|
"AND p.status = :status " +
|
||||||
|
"AND (p.description LIKE '%标准版%' OR p.description LIKE '%专业版%' OR p.description LIKE '%会员%') " +
|
||||||
|
"ORDER BY p.paidAt DESC, p.createdAt DESC")
|
||||||
|
List<Payment> findLatestSuccessfulSubscriptionByUserId(@Param("userId") Long userId, @Param("status") PaymentStatus status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,3 +71,6 @@ public interface TaskStatusRepository extends JpaRepository<TaskStatus, Long> {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ public class PlainTextPasswordEncoder implements PasswordEncoder {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -403,30 +403,50 @@ public class PaymentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据支付金额增加积分
|
* 根据支付信息增加积分
|
||||||
*/
|
*/
|
||||||
private void addPointsForPayment(Payment payment) {
|
private void addPointsForPayment(Payment payment) {
|
||||||
try {
|
try {
|
||||||
BigDecimal amount = payment.getAmount();
|
BigDecimal amount = payment.getAmount();
|
||||||
|
String description = payment.getDescription() != null ? payment.getDescription() : "";
|
||||||
Integer pointsToAdd = 0;
|
Integer pointsToAdd = 0;
|
||||||
|
|
||||||
// 根据支付金额确定积分奖励
|
// 优先从描述中识别套餐类型
|
||||||
if (amount.compareTo(new BigDecimal("59.00")) >= 0 && amount.compareTo(new BigDecimal("259.00")) < 0) {
|
if (description.contains("标准版") || description.contains("standard")) {
|
||||||
// 标准版订阅 (59-258元) - 200积分
|
// 标准版订阅 - 200积分
|
||||||
pointsToAdd = 200;
|
pointsToAdd = 200;
|
||||||
} else if (amount.compareTo(new BigDecimal("259.00")) >= 0) {
|
logger.info("识别到标准版订阅,奖励 200 积分");
|
||||||
// 专业版订阅 (259元以上) - 1000积分
|
} else if (description.contains("专业版") || description.contains("premium")) {
|
||||||
|
// 专业版订阅 - 1000积分
|
||||||
pointsToAdd = 1000;
|
pointsToAdd = 1000;
|
||||||
|
logger.info("识别到专业版订阅,奖励 1000 积分");
|
||||||
|
} else {
|
||||||
|
// 如果描述中没有套餐信息,根据金额判断
|
||||||
|
// 标准版订阅 (59-258元) - 200积分
|
||||||
|
if (amount.compareTo(new BigDecimal("59.00")) >= 0 && amount.compareTo(new BigDecimal("259.00")) < 0) {
|
||||||
|
pointsToAdd = 200;
|
||||||
|
logger.info("根据金额 {} 判断为标准版订阅,奖励 200 积分", amount);
|
||||||
|
}
|
||||||
|
// 专业版订阅 (259元以上) - 1000积分
|
||||||
|
else if (amount.compareTo(new BigDecimal("259.00")) >= 0) {
|
||||||
|
pointsToAdd = 1000;
|
||||||
|
logger.info("根据金额 {} 判断为专业版订阅,奖励 1000 积分", amount);
|
||||||
|
} else {
|
||||||
|
logger.warn("支付金额 {} 不在已知套餐范围内,不增加积分", amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pointsToAdd > 0) {
|
if (pointsToAdd > 0) {
|
||||||
userService.addPoints(payment.getUser().getId(), pointsToAdd);
|
userService.addPoints(payment.getUser().getId(), pointsToAdd);
|
||||||
logger.info("用户 {} 支付 {} 元,获得 {} 积分",
|
logger.info("✅ 用户 {} 支付 {} 元,成功获得 {} 积分",
|
||||||
payment.getUser().getUsername(), amount, pointsToAdd);
|
payment.getUser().getUsername(), amount, pointsToAdd);
|
||||||
|
} else {
|
||||||
|
logger.warn("⚠️ 用户 {} 支付 {} 元,但未获得积分(描述: {})",
|
||||||
|
payment.getUser().getUsername(), amount, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("增加积分失败:", e);
|
logger.error("❌ 增加积分失败:", e);
|
||||||
// 不抛出异常,避免影响支付流程
|
// 不抛出异常,避免影响支付流程
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,17 +86,41 @@ public class RealAIService {
|
|||||||
.body(requestBody)
|
.body(requestBody)
|
||||||
.asString();
|
.asString();
|
||||||
|
|
||||||
if (response.getStatus() == 200 && response.getBody() != null) {
|
// 添加响应调试日志
|
||||||
@SuppressWarnings("unchecked")
|
logger.info("API响应状态: {}", response.getStatus());
|
||||||
Map<String, Object> responseBody = objectMapper.readValue(response.getBody(), Map.class);
|
String responseBodyStr = response.getBody();
|
||||||
Integer code = (Integer) responseBody.get("code");
|
logger.info("API响应内容(前500字符): {}", responseBodyStr != null && responseBodyStr.length() > 500 ?
|
||||||
|
responseBodyStr.substring(0, 500) : responseBodyStr);
|
||||||
|
|
||||||
|
if (response.getStatus() == 200 && responseBodyStr != null) {
|
||||||
|
// 检查响应是否为HTML(可能是认证失败或API端点错误)
|
||||||
|
String trimmedResponse = responseBodyStr.trim();
|
||||||
|
String lowerResponse = trimmedResponse.toLowerCase();
|
||||||
|
if (lowerResponse.startsWith("<!") || lowerResponse.startsWith("<html") ||
|
||||||
|
lowerResponse.contains("<!doctype") || (!trimmedResponse.startsWith("{") && !trimmedResponse.startsWith("["))) {
|
||||||
|
logger.error("API返回HTML页面而不是JSON,可能是认证失败或API端点错误");
|
||||||
|
logger.error("响应前100字符: {}", trimmedResponse.length() > 100 ? trimmedResponse.substring(0, 100) : trimmedResponse);
|
||||||
|
logger.error("请检查:1) API密钥是否正确 2) API端点URL是否正确 3) API服务是否正常运行");
|
||||||
|
throw new RuntimeException("API返回HTML页面,可能是认证失败。请检查API密钥和端点配置");
|
||||||
|
}
|
||||||
|
|
||||||
if (code != null && code == 200) {
|
try {
|
||||||
logger.info("图生视频任务提交成功: {}", responseBody);
|
@SuppressWarnings("unchecked")
|
||||||
return responseBody;
|
Map<String, Object> responseBody = objectMapper.readValue(responseBodyStr, Map.class);
|
||||||
} else {
|
Integer code = (Integer) responseBody.get("code");
|
||||||
logger.error("图生视频任务提交失败: {}", responseBody);
|
|
||||||
throw new RuntimeException("任务提交失败: " + responseBody.get("message"));
|
if (code != null && code == 200) {
|
||||||
|
logger.info("图生视频任务提交成功: {}", responseBody);
|
||||||
|
return responseBody;
|
||||||
|
} else {
|
||||||
|
logger.error("图生视频任务提交失败: {}", responseBody);
|
||||||
|
throw new RuntimeException("任务提交失败: " + responseBody.get("message"));
|
||||||
|
}
|
||||||
|
} catch (com.fasterxml.jackson.core.JsonParseException e) {
|
||||||
|
logger.error("解析API响应为JSON失败,响应内容可能是HTML或其他格式", e);
|
||||||
|
logger.error("响应内容前200字符: {}", responseBodyStr.length() > 200 ?
|
||||||
|
responseBodyStr.substring(0, 200) : responseBodyStr);
|
||||||
|
throw new RuntimeException("API返回非JSON响应,可能是认证失败。请检查API密钥和端点配置");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.error("图生视频任务提交失败,HTTP状态: {}", response.getStatus());
|
logger.error("图生视频任务提交失败,HTTP状态: {}", response.getStatus());
|
||||||
@@ -120,21 +144,25 @@ public class RealAIService {
|
|||||||
try {
|
try {
|
||||||
// 根据参数选择可用的模型
|
// 根据参数选择可用的模型
|
||||||
String modelName = selectAvailableTextToVideoModel(aspectRatio, duration, hdMode);
|
String modelName = selectAvailableTextToVideoModel(aspectRatio, duration, hdMode);
|
||||||
|
|
||||||
// 根据分辨率选择size参数
|
|
||||||
String size = convertAspectRatioToSize(aspectRatio, hdMode);
|
|
||||||
|
|
||||||
// 添加调试日志
|
// 添加调试日志
|
||||||
logger.info("提交文生视频任务请求: model={}, prompt={}, size={}, seconds={}",
|
logger.info("提交文生视频任务请求: model={}, prompt={}, aspectRatio={}, duration={}, hd={}",
|
||||||
modelName, prompt, size, duration);
|
modelName, prompt, aspectRatio, duration, hdMode);
|
||||||
logger.info("选择的模型: {}", modelName);
|
logger.info("选择的模型: {}", modelName);
|
||||||
logger.info("API端点: {}", aiApiBaseUrl + "/user/ai/tasks/submit");
|
logger.info("API端点: {}", aiApiBaseUrl + "/v2/videos/generations");
|
||||||
logger.info("使用API密钥: {}", aiApiKey.substring(0, Math.min(10, aiApiKey.length())) + "...");
|
logger.info("使用API密钥: {}", aiApiKey.substring(0, Math.min(10, aiApiKey.length())) + "...");
|
||||||
|
|
||||||
String url = aiApiBaseUrl + "/user/ai/tasks/submit";
|
String url = aiApiBaseUrl + "/v2/videos/generations";
|
||||||
String requestBody = String.format("{\"modelName\":\"%s\",\"prompt\":\"%s\",\"aspectRatio\":\"%s\",\"imageToVideo\":false}",
|
|
||||||
modelName, prompt, aspectRatio);
|
|
||||||
|
|
||||||
|
// 构建请求体(参考Comfly项目的格式)
|
||||||
|
Map<String, Object> requestBodyMap = new HashMap<>();
|
||||||
|
requestBodyMap.put("prompt", prompt);
|
||||||
|
requestBodyMap.put("model", modelName);
|
||||||
|
requestBodyMap.put("aspect_ratio", aspectRatio);
|
||||||
|
requestBodyMap.put("duration", duration);
|
||||||
|
requestBodyMap.put("hd", hdMode);
|
||||||
|
|
||||||
|
String requestBody = objectMapper.writeValueAsString(requestBodyMap);
|
||||||
logger.info("请求体: {}", requestBody);
|
logger.info("请求体: {}", requestBody);
|
||||||
|
|
||||||
HttpResponse<String> response = Unirest.post(url)
|
HttpResponse<String> response = Unirest.post(url)
|
||||||
@@ -145,19 +173,44 @@ public class RealAIService {
|
|||||||
|
|
||||||
// 添加响应调试日志
|
// 添加响应调试日志
|
||||||
logger.info("API响应状态: {}", response.getStatus());
|
logger.info("API响应状态: {}", response.getStatus());
|
||||||
logger.info("API响应内容: {}", response.getBody());
|
String responseBodyStr = response.getBody();
|
||||||
|
logger.info("API响应内容(前500字符): {}", responseBodyStr != null && responseBodyStr.length() > 500 ?
|
||||||
|
responseBodyStr.substring(0, 500) : responseBodyStr);
|
||||||
|
|
||||||
if (response.getStatus() == 200 && response.getBody() != null) {
|
if (response.getStatus() == 200 && responseBodyStr != null) {
|
||||||
@SuppressWarnings("unchecked")
|
// 检查响应是否为HTML(可能是认证失败或API端点错误)
|
||||||
Map<String, Object> responseBody = objectMapper.readValue(response.getBody(), Map.class);
|
String trimmedResponse = responseBodyStr.trim();
|
||||||
Integer code = (Integer) responseBody.get("code");
|
String lowerResponse = trimmedResponse.toLowerCase();
|
||||||
|
if (lowerResponse.startsWith("<!") || lowerResponse.startsWith("<html") ||
|
||||||
|
lowerResponse.contains("<!doctype") || (!trimmedResponse.startsWith("{") && !trimmedResponse.startsWith("["))) {
|
||||||
|
logger.error("API返回HTML页面而不是JSON,可能是认证失败或API端点错误");
|
||||||
|
logger.error("响应前100字符: {}", trimmedResponse.length() > 100 ? trimmedResponse.substring(0, 100) : trimmedResponse);
|
||||||
|
logger.error("请检查:1) API密钥是否正确 2) API端点URL是否正确 3) API服务是否正常运行");
|
||||||
|
throw new RuntimeException("API返回HTML页面,可能是认证失败。请检查API密钥和端点配置");
|
||||||
|
}
|
||||||
|
|
||||||
if (code != null && code == 200) {
|
try {
|
||||||
logger.info("文生视频任务提交成功: {}", responseBody);
|
@SuppressWarnings("unchecked")
|
||||||
return responseBody;
|
Map<String, Object> responseBody = objectMapper.readValue(responseBodyStr, Map.class);
|
||||||
} else {
|
|
||||||
logger.error("文生视频任务提交失败: {}", responseBody);
|
// 参考Comfly项目,响应格式为 {"task_id": "xxx"}
|
||||||
throw new RuntimeException("任务提交失败: " + responseBody.get("message"));
|
if (responseBody.containsKey("task_id")) {
|
||||||
|
logger.info("文生视频任务提交成功,task_id: {}", responseBody.get("task_id"));
|
||||||
|
// 转换为统一的响应格式
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put("code", 200);
|
||||||
|
result.put("data", responseBody);
|
||||||
|
result.put("task_id", responseBody.get("task_id"));
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
logger.error("文生视频任务提交失败,响应中缺少task_id: {}", responseBody);
|
||||||
|
throw new RuntimeException("任务提交失败: 响应格式不正确");
|
||||||
|
}
|
||||||
|
} catch (com.fasterxml.jackson.core.JsonParseException e) {
|
||||||
|
logger.error("解析API响应为JSON失败,响应内容可能是HTML或其他格式", e);
|
||||||
|
logger.error("响应内容前200字符: {}", responseBodyStr.length() > 200 ?
|
||||||
|
responseBodyStr.substring(0, 200) : responseBodyStr);
|
||||||
|
throw new RuntimeException("API返回非JSON响应,可能是认证失败。请检查API密钥和端点配置");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.error("文生视频任务提交失败,HTTP状态: {}", response.getStatus());
|
logger.error("文生视频任务提交失败,HTTP状态: {}", response.getStatus());
|
||||||
@@ -175,25 +228,34 @@ public class RealAIService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询任务状态
|
* 查询任务状态
|
||||||
|
* 参考Comfly项目,使用 /v2/videos/generations/{task_id} 端点
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> getTaskStatus(String taskId) {
|
public Map<String, Object> getTaskStatus(String taskId) {
|
||||||
try {
|
try {
|
||||||
String url = aiApiBaseUrl + "/user/ai/tasks/" + taskId;
|
String url = aiApiBaseUrl + "/v2/videos/generations/" + taskId;
|
||||||
|
logger.debug("查询任务状态: {}", url);
|
||||||
HttpResponse<String> response = Unirest.get(url)
|
HttpResponse<String> response = Unirest.get(url)
|
||||||
.header("Authorization", "Bearer " + aiApiKey)
|
.header("Authorization", "Bearer " + aiApiKey)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
.asString();
|
.asString();
|
||||||
|
|
||||||
if (response.getStatus() == 200 && response.getBody() != null) {
|
if (response.getStatus() == 200 && response.getBody() != null) {
|
||||||
@SuppressWarnings("unchecked")
|
String responseBodyStr = response.getBody();
|
||||||
Map<String, Object> responseBody = objectMapper.readValue(response.getBody(), Map.class);
|
logger.info("查询任务状态API响应(前500字符): {}",
|
||||||
Integer code = (Integer) responseBody.get("code");
|
responseBodyStr != null && responseBodyStr.length() > 500 ?
|
||||||
|
responseBodyStr.substring(0, 500) : responseBodyStr);
|
||||||
|
|
||||||
if (code != null && code == 200) {
|
@SuppressWarnings("unchecked")
|
||||||
return responseBody;
|
Map<String, Object> responseBody = objectMapper.readValue(responseBodyStr, Map.class);
|
||||||
} else {
|
|
||||||
logger.error("查询任务状态失败: {}", responseBody);
|
logger.info("解析后的任务状态响应: {}", responseBody);
|
||||||
throw new RuntimeException("查询任务状态失败: " + responseBody.get("message"));
|
|
||||||
}
|
// 参考Comfly项目,响应格式为 {"status": "SUCCESS", "data": {"output": "video_url"}, ...}
|
||||||
|
// 转换为统一的响应格式
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put("code", 200);
|
||||||
|
result.put("data", responseBody);
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
logger.error("查询任务状态失败,HTTP状态: {}", response.getStatus());
|
logger.error("查询任务状态失败,HTTP状态: {}", response.getStatus());
|
||||||
throw new RuntimeException("查询任务状态失败,HTTP状态: " + response.getStatus());
|
throw new RuntimeException("查询任务状态失败,HTTP状态: " + response.getStatus());
|
||||||
@@ -273,41 +335,13 @@ public class RealAIService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取可用的模型列表
|
* 获取可用的模型列表
|
||||||
|
* 注意:Comfly项目可能不需要这个端点,直接使用默认模型选择逻辑
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> getAvailableModels() {
|
public Map<String, Object> getAvailableModels() {
|
||||||
try {
|
// 暂时不调用模型列表API,直接返回null让调用方使用默认逻辑
|
||||||
String url = aiApiBaseUrl + "/user/ai/models";
|
// 因为Comfly项目直接使用sora-2或sora-2-pro,不需要查询模型列表
|
||||||
logger.info("正在调用外部API获取模型列表: {}", url);
|
logger.debug("跳过模型列表查询,直接使用默认模型选择逻辑");
|
||||||
logger.info("使用API密钥: {}", aiApiKey.substring(0, Math.min(10, aiApiKey.length())) + "...");
|
return null;
|
||||||
|
|
||||||
HttpResponse<String> response = Unirest.get(url)
|
|
||||||
.header("Authorization", "Bearer " + aiApiKey)
|
|
||||||
.asString();
|
|
||||||
|
|
||||||
logger.info("API响应状态: {}", response.getStatus());
|
|
||||||
logger.info("API响应内容: {}", response.getBody());
|
|
||||||
|
|
||||||
if (response.getStatus() == 200 && response.getBody() != null) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> responseBody = objectMapper.readValue(response.getBody(), Map.class);
|
|
||||||
Integer code = (Integer) responseBody.get("code");
|
|
||||||
if (code != null && code == 200) {
|
|
||||||
logger.info("成功获取模型列表");
|
|
||||||
return responseBody;
|
|
||||||
} else {
|
|
||||||
logger.error("API返回错误代码: {}, 响应: {}", code, responseBody);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.error("API调用失败,HTTP状态: {}, 响应: {}", response.getStatus(), response.getBody());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} catch (UnirestException e) {
|
|
||||||
logger.error("获取模型列表失败", e);
|
|
||||||
return null;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("获取模型列表失败", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -362,15 +396,17 @@ public class RealAIService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据参数选择文生视频模型(默认逻辑)
|
* 根据参数选择文生视频模型(默认逻辑)
|
||||||
|
* 参考Comfly项目,使用 sora-2 或 sora-2-pro
|
||||||
*/
|
*/
|
||||||
private String selectTextToVideoModel(String aspectRatio, String duration, boolean hdMode) {
|
private String selectTextToVideoModel(String aspectRatio, String duration, boolean hdMode) {
|
||||||
String size = hdMode ? "large" : "small";
|
// 参考Comfly项目:
|
||||||
String orientation = "9:16".equals(aspectRatio) || "3:4".equals(aspectRatio) ? "portrait" : "landscape";
|
// - sora-2: 支持10s和15s,不支持25s和HD
|
||||||
|
// - sora-2-pro: 支持10s、15s和25s,支持HD
|
||||||
// 根据API返回的模型列表,只支持10s和15s
|
if ("25".equals(duration) || hdMode) {
|
||||||
String actualDuration = "5".equals(duration) ? "10" : duration;
|
return "sora-2-pro";
|
||||||
|
}
|
||||||
return String.format("sc_sora2_text_%s_%ss_%s", orientation, actualDuration, size);
|
// aspectRatio参数未使用,但保留以保持方法签名一致
|
||||||
|
return "sora-2";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -397,31 +433,37 @@ public class RealAIService {
|
|||||||
* @return API响应,包含多张图片的URL
|
* @return API响应,包含多张图片的URL
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> submitTextToImageTask(String prompt, String aspectRatio, int numImages) {
|
public Map<String, Object> submitTextToImageTask(String prompt, String aspectRatio, int numImages) {
|
||||||
|
return submitTextToImageTask(prompt, aspectRatio, numImages, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交文生图任务(使用banana模型)
|
||||||
|
* 参考Comfly项目的Comfly_nano_banana_edit节点实现
|
||||||
|
*/
|
||||||
|
public Map<String, Object> submitTextToImageTask(String prompt, String aspectRatio, int numImages, boolean hdMode) {
|
||||||
try {
|
try {
|
||||||
logger.info("提交文生图任务: prompt={}, aspectRatio={}, numImages={}", prompt, aspectRatio, numImages);
|
logger.info("提交文生图任务(banana模型): prompt={}, aspectRatio={}, hdMode={}",
|
||||||
|
prompt, aspectRatio, hdMode);
|
||||||
|
|
||||||
// 限制生成图片数量在1-12之间,参考Comfly项目的限制
|
// 注意:banana模型一次只生成1张图片,numImages参数用于兼容性,实际请求中不使用
|
||||||
if (numImages < 1) {
|
// 参考Comfly_nano_banana_edit节点:每次调用只生成1张图片
|
||||||
numImages = 1;
|
|
||||||
} else if (numImages > 12) {
|
|
||||||
numImages = 12;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据aspectRatio转换尺寸,参考Comfly项目的尺寸映射
|
|
||||||
String size = convertAspectRatioToImageSize(aspectRatio);
|
|
||||||
|
|
||||||
// 使用文生图的API端点(Comfly API)
|
// 使用文生图的API端点(Comfly API)
|
||||||
|
// 参考Comfly_nano_banana_edit节点:使用 /v1/images/generations 端点
|
||||||
String url = aiImageApiBaseUrl + "/v1/images/generations";
|
String url = aiImageApiBaseUrl + "/v1/images/generations";
|
||||||
|
|
||||||
// 构建请求体,参考Comfly_qwen_image节点的参数设置
|
// 根据hdMode选择模型:参考Comfly_nano_banana_edit节点
|
||||||
|
// nano-banana: 标准模式
|
||||||
|
// nano-banana-hd: 高清模式
|
||||||
|
String model = hdMode ? "nano-banana-hd" : "nano-banana";
|
||||||
|
|
||||||
|
// 构建请求体,参考Comfly_nano_banana_edit节点的参数设置
|
||||||
|
// 注意:banana模型不需要n参数,每次只生成1张图片
|
||||||
Map<String, Object> requestBody = new HashMap<>();
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
requestBody.put("prompt", prompt);
|
requestBody.put("prompt", prompt);
|
||||||
requestBody.put("size", size);
|
requestBody.put("model", model);
|
||||||
requestBody.put("model", "qwen-image");
|
requestBody.put("aspect_ratio", aspectRatio); // 直接使用aspect_ratio,不需要转换为size
|
||||||
requestBody.put("n", numImages); // 支持生成多张图片
|
requestBody.put("response_format", "url"); // 可选:url 或 b64_json
|
||||||
requestBody.put("response_format", "url");
|
|
||||||
// 添加guidance_scale参数以提高图片质量(参考Comfly项目)
|
|
||||||
requestBody.put("guidance_scale", 2.5);
|
|
||||||
|
|
||||||
String requestBodyJson = objectMapper.writeValueAsString(requestBody);
|
String requestBodyJson = objectMapper.writeValueAsString(requestBody);
|
||||||
|
|
||||||
@@ -436,19 +478,54 @@ public class RealAIService {
|
|||||||
.asString();
|
.asString();
|
||||||
|
|
||||||
logger.info("文生图API响应状态: {}", response.getStatus());
|
logger.info("文生图API响应状态: {}", response.getStatus());
|
||||||
logger.info("文生图API响应内容: {}", response.getBody());
|
String responseBodyStr = response.getBody();
|
||||||
|
logger.info("文生图API响应内容(前500字符): {}", responseBodyStr != null && responseBodyStr.length() > 500 ?
|
||||||
|
responseBodyStr.substring(0, 500) : responseBodyStr);
|
||||||
|
|
||||||
if (response.getStatus() == 200 && response.getBody() != null) {
|
if (response.getStatus() == 200 && responseBodyStr != null) {
|
||||||
@SuppressWarnings("unchecked")
|
// 检查响应是否为HTML(可能是认证失败或API端点错误)
|
||||||
Map<String, Object> responseBody = objectMapper.readValue(response.getBody(), Map.class);
|
String trimmedResponse = responseBodyStr.trim();
|
||||||
|
String lowerResponse = trimmedResponse.toLowerCase();
|
||||||
|
if (lowerResponse.startsWith("<!") || lowerResponse.startsWith("<html") ||
|
||||||
|
lowerResponse.contains("<!doctype") || (!trimmedResponse.startsWith("{") && !trimmedResponse.startsWith("["))) {
|
||||||
|
logger.error("API返回HTML页面而不是JSON,可能是认证失败或API端点错误");
|
||||||
|
logger.error("响应前100字符: {}", trimmedResponse.length() > 100 ? trimmedResponse.substring(0, 100) : trimmedResponse);
|
||||||
|
logger.error("请检查:1) API密钥是否正确 2) API端点URL是否正确 3) API服务是否正常运行");
|
||||||
|
throw new RuntimeException("API返回HTML页面,可能是认证失败。请检查API密钥和端点配置");
|
||||||
|
}
|
||||||
|
|
||||||
// 检查是否有data字段
|
try {
|
||||||
if (responseBody.get("data") != null) {
|
@SuppressWarnings("unchecked")
|
||||||
logger.info("文生图任务提交成功: {}", responseBody);
|
Map<String, Object> responseBody = objectMapper.readValue(responseBodyStr, Map.class);
|
||||||
return responseBody;
|
|
||||||
} else {
|
// 检查是否有data字段且不为空(参考Comfly_nano_banana_edit节点的响应处理)
|
||||||
logger.error("文生图任务提交失败: {}", responseBody);
|
Object dataObj = responseBody.get("data");
|
||||||
throw new RuntimeException("任务提交失败: " + responseBody.get("message"));
|
if (dataObj != null) {
|
||||||
|
// 检查data是否为列表且不为空
|
||||||
|
if (dataObj instanceof List) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<Map<String, Object>> dataList = (List<Map<String, Object>>) dataObj;
|
||||||
|
if (dataList.isEmpty()) {
|
||||||
|
logger.error("文生图任务提交失败: data字段为空列表");
|
||||||
|
throw new RuntimeException("任务提交失败: API返回空的data列表");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.info("文生图任务提交成功: {}", responseBody);
|
||||||
|
return responseBody;
|
||||||
|
} else {
|
||||||
|
logger.error("文生图任务提交失败: 响应中没有data字段,响应内容: {}", responseBody);
|
||||||
|
Object errorMessage = responseBody.get("message");
|
||||||
|
if (errorMessage != null) {
|
||||||
|
throw new RuntimeException("任务提交失败: " + errorMessage);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("任务提交失败: API响应中没有data字段");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (com.fasterxml.jackson.core.JsonParseException e) {
|
||||||
|
logger.error("解析API响应为JSON失败,响应内容可能是HTML或其他格式", e);
|
||||||
|
logger.error("响应内容前200字符: {}", responseBodyStr.length() > 200 ?
|
||||||
|
responseBodyStr.substring(0, 200) : responseBodyStr);
|
||||||
|
throw new RuntimeException("API返回非JSON响应,可能是认证失败。请检查API密钥和端点配置");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.error("文生图任务提交失败,HTTP状态: {}", response.getStatus());
|
logger.error("文生图任务提交失败,HTTP状态: {}", response.getStatus());
|
||||||
|
|||||||
@@ -100,60 +100,113 @@ public class StoryboardVideoService {
|
|||||||
taskRepository.flush(); // 强制刷新到数据库
|
taskRepository.flush(); // 强制刷新到数据库
|
||||||
|
|
||||||
// 调用真实文生图API,生成多张分镜图
|
// 调用真实文生图API,生成多张分镜图
|
||||||
|
// 参考Comfly项目:如果API不支持一次生成多张图片,则多次调用生成多张
|
||||||
logger.info("分镜视频任务已提交,正在调用文生图API生成{}张分镜图...", DEFAULT_STORYBOARD_IMAGES);
|
logger.info("分镜视频任务已提交,正在调用文生图API生成{}张分镜图...", DEFAULT_STORYBOARD_IMAGES);
|
||||||
|
|
||||||
Map<String, Object> apiResponse = realAIService.submitTextToImageTask(
|
// 收集所有图片URL
|
||||||
task.getPrompt(),
|
List<String> imageUrls = new ArrayList<>();
|
||||||
task.getAspectRatio(),
|
|
||||||
DEFAULT_STORYBOARD_IMAGES // 生成多张图片用于分镜图
|
|
||||||
);
|
|
||||||
|
|
||||||
// 从API响应中提取所有图片URL
|
// 参考Comfly项目:多次调用API生成多张图片(因为Comfly API可能不支持一次生成多张)
|
||||||
@SuppressWarnings("unchecked")
|
for (int i = 0; i < DEFAULT_STORYBOARD_IMAGES; i++) {
|
||||||
List<Map<String, Object>> data = (List<Map<String, Object>>) apiResponse.get("data");
|
try {
|
||||||
if (data != null && !data.isEmpty()) {
|
logger.info("生成第{}张分镜图(共{}张)...", i + 1, DEFAULT_STORYBOARD_IMAGES);
|
||||||
// 收集所有图片URL
|
|
||||||
List<String> imageUrls = new ArrayList<>();
|
// 每次调用生成1张图片,使用banana模型
|
||||||
for (Map<String, Object> imageData : data) {
|
Map<String, Object> apiResponse = realAIService.submitTextToImageTask(
|
||||||
String imageUrl = null;
|
task.getPrompt(),
|
||||||
if (imageData.get("url") != null) {
|
task.getAspectRatio(),
|
||||||
imageUrl = (String) imageData.get("url");
|
1, // 每次生成1张图片
|
||||||
} else if (imageData.get("b64_json") != null) {
|
task.isHdMode() // 使用任务的hdMode参数选择模型
|
||||||
// base64编码的图片
|
);
|
||||||
String base64Data = (String) imageData.get("b64_json");
|
|
||||||
imageUrl = "data:image/png;base64," + base64Data;
|
// 检查API响应是否为空
|
||||||
|
if (apiResponse == null) {
|
||||||
|
logger.warn("第{}张图片API响应为null,跳过", i + 1);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (imageUrl != null) {
|
|
||||||
imageUrls.add(imageUrl);
|
// 从API响应中提取图片URL
|
||||||
|
// 参考Comfly_nano_banana_edit节点:响应格式为 {"data": [{"url": "...", "b64_json": "..."}]}
|
||||||
|
Object dataObj = apiResponse.get("data");
|
||||||
|
if (dataObj instanceof List) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<Map<String, Object>> data = (List<Map<String, Object>>) dataObj;
|
||||||
|
if (!data.isEmpty()) {
|
||||||
|
// 提取第一张图片的URL(因为每次只生成1张)
|
||||||
|
Map<String, Object> imageData = data.get(0);
|
||||||
|
if (imageData == null) {
|
||||||
|
logger.warn("第{}张图片data第一个元素为null,跳过", i + 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String imageUrl = null;
|
||||||
|
Object urlObj = imageData.get("url");
|
||||||
|
Object b64JsonObj = imageData.get("b64_json");
|
||||||
|
|
||||||
|
if (urlObj != null) {
|
||||||
|
imageUrl = urlObj.toString();
|
||||||
|
} else if (b64JsonObj != null) {
|
||||||
|
// base64编码的图片
|
||||||
|
String base64Data = b64JsonObj.toString();
|
||||||
|
imageUrl = "data:image/png;base64," + base64Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageUrl != null && !imageUrl.isEmpty()) {
|
||||||
|
imageUrls.add(imageUrl);
|
||||||
|
logger.info("成功获取第{}张分镜图", i + 1);
|
||||||
|
} else {
|
||||||
|
logger.warn("第{}张图片URL为空,跳过", i + 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.warn("第{}张图片API响应data为空列表,跳过", i + 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.warn("第{}张图片API响应data格式不正确(不是列表),跳过", i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 在多次调用之间添加短暂延迟,避免API限流
|
||||||
|
if (i < DEFAULT_STORYBOARD_IMAGES - 1) {
|
||||||
|
Thread.sleep(500); // 延迟500ms
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("生成第{}张分镜图失败: {}", i + 1, e.getMessage());
|
||||||
|
// 继续生成其他图片,不因单张失败而终止整个流程
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageUrls.isEmpty()) {
|
|
||||||
throw new RuntimeException("未能从API响应中提取任何图片URL");
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("成功获取{}张图片,开始拼接成分镜图网格...", imageUrls.size());
|
|
||||||
|
|
||||||
// 拼接多张图片成网格
|
|
||||||
String mergedImageUrl = imageGridService.mergeImagesToGrid(imageUrls, 0); // 0表示自动计算列数
|
|
||||||
|
|
||||||
// 重新加载任务(因为之前的flush可能使实体detached)
|
|
||||||
task = taskRepository.findByTaskId(taskId)
|
|
||||||
.orElseThrow(() -> new RuntimeException("任务未找到: " + taskId));
|
|
||||||
|
|
||||||
// 设置拼接后的结果图片URL
|
|
||||||
task.setResultUrl(mergedImageUrl);
|
|
||||||
task.setRealTaskId(taskId + "_image");
|
|
||||||
task.updateStatus(StoryboardVideoTask.TaskStatus.COMPLETED);
|
|
||||||
task.updateProgress(100);
|
|
||||||
|
|
||||||
taskRepository.save(task);
|
|
||||||
|
|
||||||
logger.info("分镜图生成并拼接完成,任务ID: {}, 共生成{}张图片", taskId, imageUrls.size());
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("API返回的图片数据为空");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (imageUrls.isEmpty()) {
|
||||||
|
throw new RuntimeException("未能从API响应中提取任何图片URL");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageUrls.size() < DEFAULT_STORYBOARD_IMAGES) {
|
||||||
|
logger.warn("只生成了{}张图片,少于预期的{}张", imageUrls.size(), DEFAULT_STORYBOARD_IMAGES);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("成功获取{}张图片,开始拼接成分镜图网格...", imageUrls.size());
|
||||||
|
|
||||||
|
// 拼接多张图片成网格
|
||||||
|
String mergedImageUrl = imageGridService.mergeImagesToGrid(imageUrls, 0); // 0表示自动计算列数
|
||||||
|
|
||||||
|
// 检查拼接后的图片URL是否有效
|
||||||
|
if (mergedImageUrl == null || mergedImageUrl.isEmpty()) {
|
||||||
|
throw new RuntimeException("图片拼接失败: 返回的图片URL为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新加载任务(因为之前的flush可能使实体detached)
|
||||||
|
task = taskRepository.findByTaskId(taskId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("任务未找到: " + taskId));
|
||||||
|
|
||||||
|
// 设置拼接后的结果图片URL
|
||||||
|
task.setResultUrl(mergedImageUrl);
|
||||||
|
task.setRealTaskId(taskId + "_image");
|
||||||
|
task.updateStatus(StoryboardVideoTask.TaskStatus.COMPLETED);
|
||||||
|
task.updateProgress(100);
|
||||||
|
|
||||||
|
taskRepository.save(task);
|
||||||
|
|
||||||
|
logger.info("分镜图生成并拼接完成,任务ID: {}, 共生成{}张图片", taskId, imageUrls.size());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("处理分镜视频任务失败: {}", taskId, e);
|
logger.error("处理分镜视频任务失败: {}", taskId, e);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -171,6 +171,8 @@ public class TaskQueueService {
|
|||||||
apiResponse = processImageToVideoTask(taskQueue);
|
apiResponse = processImageToVideoTask(taskQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("收到API响应,准备提取任务ID: taskId={}, response={}", taskQueue.getTaskId(), apiResponse);
|
||||||
|
|
||||||
// 提取真实任务ID
|
// 提取真实任务ID
|
||||||
String realTaskId = extractRealTaskId(apiResponse);
|
String realTaskId = extractRealTaskId(apiResponse);
|
||||||
if (realTaskId != null) {
|
if (realTaskId != null) {
|
||||||
@@ -178,6 +180,7 @@ public class TaskQueueService {
|
|||||||
taskQueueRepository.save(taskQueue);
|
taskQueueRepository.save(taskQueue);
|
||||||
logger.info("任务 {} 已提交到外部API,真实任务ID: {}", taskQueue.getTaskId(), realTaskId);
|
logger.info("任务 {} 已提交到外部API,真实任务ID: {}", taskQueue.getTaskId(), realTaskId);
|
||||||
} else {
|
} else {
|
||||||
|
logger.error("无法提取任务ID,API响应: {}", apiResponse);
|
||||||
throw new RuntimeException("API未返回有效的任务ID");
|
throw new RuntimeException("API未返回有效的任务ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,32 +292,89 @@ public class TaskQueueService {
|
|||||||
* 从API响应中提取真实任务ID
|
* 从API响应中提取真实任务ID
|
||||||
*/
|
*/
|
||||||
private String extractRealTaskId(Map<String, Object> apiResponse) {
|
private String extractRealTaskId(Map<String, Object> apiResponse) {
|
||||||
if (apiResponse == null || !apiResponse.containsKey("data")) {
|
if (apiResponse == null) {
|
||||||
|
logger.warn("API响应为null,无法提取任务ID");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("提取任务ID,API响应键: {}", apiResponse.keySet());
|
||||||
|
|
||||||
|
// 首先检查顶层是否有task_id(新API格式)
|
||||||
|
if (apiResponse.containsKey("task_id")) {
|
||||||
|
Object taskIdObj = apiResponse.get("task_id");
|
||||||
|
logger.debug("找到顶层task_id: {} (类型: {})", taskIdObj, taskIdObj != null ? taskIdObj.getClass().getName() : "null");
|
||||||
|
if (taskIdObj != null) {
|
||||||
|
String taskId = taskIdObj.toString();
|
||||||
|
logger.info("提取到任务ID: {}", taskId);
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 然后检查data字段
|
||||||
|
if (!apiResponse.containsKey("data")) {
|
||||||
|
logger.warn("API响应中没有data字段,也无法找到顶层task_id");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object data = apiResponse.get("data");
|
Object data = apiResponse.get("data");
|
||||||
|
logger.debug("data字段类型: {}", data != null ? data.getClass().getName() : "null");
|
||||||
|
|
||||||
if (data instanceof Map) {
|
if (data instanceof Map) {
|
||||||
Map<?, ?> dataMap = (Map<?, ?>) data;
|
Map<?, ?> dataMap = (Map<?, ?>) data;
|
||||||
String taskNo = (String) dataMap.get("taskNo");
|
logger.debug("data字段是Map,键: {}", dataMap.keySet());
|
||||||
if (taskNo != null) {
|
// 检查新格式的task_id
|
||||||
|
Object taskIdObj = dataMap.get("task_id");
|
||||||
|
if (taskIdObj != null) {
|
||||||
|
String taskId = taskIdObj.toString();
|
||||||
|
logger.info("从data中提取到任务ID: {}", taskId);
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
// 检查旧格式的taskNo
|
||||||
|
Object taskNoObj = dataMap.get("taskNo");
|
||||||
|
if (taskNoObj != null) {
|
||||||
|
String taskNo = taskNoObj.toString();
|
||||||
|
logger.info("从data中提取到任务编号: {}", taskNo);
|
||||||
return taskNo;
|
return taskNo;
|
||||||
}
|
}
|
||||||
return (String) dataMap.get("taskId");
|
// 检查旧格式的taskId
|
||||||
|
Object taskIdObj2 = dataMap.get("taskId");
|
||||||
|
if (taskIdObj2 != null) {
|
||||||
|
String taskId = taskIdObj2.toString();
|
||||||
|
logger.info("从data中提取到任务ID(旧格式): {}", taskId);
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
} else if (data instanceof List) {
|
} else if (data instanceof List) {
|
||||||
List<?> dataList = (List<?>) data;
|
List<?> dataList = (List<?>) data;
|
||||||
if (!dataList.isEmpty()) {
|
if (!dataList.isEmpty()) {
|
||||||
Object firstElement = dataList.get(0);
|
Object firstElement = dataList.get(0);
|
||||||
if (firstElement instanceof Map) {
|
if (firstElement instanceof Map) {
|
||||||
Map<?, ?> firstMap = (Map<?, ?>) firstElement;
|
Map<?, ?> firstMap = (Map<?, ?>) firstElement;
|
||||||
String taskNo = (String) firstMap.get("taskNo");
|
// 检查新格式的task_id
|
||||||
if (taskNo != null) {
|
Object taskIdObj = firstMap.get("task_id");
|
||||||
|
if (taskIdObj != null) {
|
||||||
|
String taskId = taskIdObj.toString();
|
||||||
|
logger.info("从data列表第一个元素提取到任务ID: {}", taskId);
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
// 检查旧格式的taskNo
|
||||||
|
Object taskNoObj = firstMap.get("taskNo");
|
||||||
|
if (taskNoObj != null) {
|
||||||
|
String taskNo = taskNoObj.toString();
|
||||||
|
logger.info("从data列表第一个元素提取到任务编号: {}", taskNo);
|
||||||
return taskNo;
|
return taskNo;
|
||||||
}
|
}
|
||||||
return (String) firstMap.get("taskId");
|
// 检查旧格式的taskId
|
||||||
|
Object taskIdObj2 = firstMap.get("taskId");
|
||||||
|
if (taskIdObj2 != null) {
|
||||||
|
String taskId = taskIdObj2.toString();
|
||||||
|
logger.info("从data列表第一个元素提取到任务ID(旧格式): {}", taskId);
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.warn("无法从API响应中提取任务ID,响应内容: {}", apiResponse);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,45 +440,138 @@ public class TaskQueueService {
|
|||||||
|
|
||||||
if (statusResponse != null && statusResponse.containsKey("data")) {
|
if (statusResponse != null && statusResponse.containsKey("data")) {
|
||||||
Object data = statusResponse.get("data");
|
Object data = statusResponse.get("data");
|
||||||
|
logger.debug("data字段类型: {}, 值: {}", data != null ? data.getClass().getName() : "null", data);
|
||||||
|
|
||||||
Map<?, ?> taskData = null;
|
Map<?, ?> taskData = null;
|
||||||
|
|
||||||
// 处理不同的响应格式
|
// 处理不同的响应格式
|
||||||
if (data instanceof Map) {
|
if (data instanceof Map) {
|
||||||
taskData = (Map<?, ?>) data;
|
taskData = (Map<?, ?>) data;
|
||||||
|
logger.debug("taskData是Map,键: {}", taskData.keySet());
|
||||||
} else if (data instanceof List) {
|
} else if (data instanceof List) {
|
||||||
List<?> dataList = (List<?>) data;
|
List<?> dataList = (List<?>) data;
|
||||||
if (!dataList.isEmpty()) {
|
if (!dataList.isEmpty()) {
|
||||||
Object firstElement = dataList.get(0);
|
Object firstElement = dataList.get(0);
|
||||||
if (firstElement instanceof Map) {
|
if (firstElement instanceof Map) {
|
||||||
taskData = (Map<?, ?>) firstElement;
|
taskData = (Map<?, ?>) firstElement;
|
||||||
|
logger.debug("taskData是List的第一个元素,键: {}", taskData.keySet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taskData != null) {
|
if (taskData != null) {
|
||||||
String status = (String) taskData.get("status");
|
String status = (String) taskData.get("status");
|
||||||
String resultUrl = (String) taskData.get("resultUrl");
|
// 支持大小写不敏感的状态检查
|
||||||
|
if (status != null) {
|
||||||
|
status = status.toUpperCase();
|
||||||
|
}
|
||||||
|
logger.info("提取到的任务状态: {}", status);
|
||||||
|
|
||||||
|
// 提取结果URL - 支持多种格式
|
||||||
|
String resultUrl = null;
|
||||||
|
|
||||||
|
// 1. 检查嵌套的data.data.output(最深层嵌套格式)
|
||||||
|
Object nestedData = taskData.get("data");
|
||||||
|
if (nestedData instanceof Map) {
|
||||||
|
Map<?, ?> nestedDataMap = (Map<?, ?>) nestedData;
|
||||||
|
logger.debug("找到嵌套的data字段,键: {}", nestedDataMap.keySet());
|
||||||
|
Object innerData = nestedDataMap.get("data");
|
||||||
|
if (innerData instanceof Map) {
|
||||||
|
Map<?, ?> innerDataMap = (Map<?, ?>) innerData;
|
||||||
|
logger.debug("找到深层嵌套的data字段,键: {}", innerDataMap.keySet());
|
||||||
|
Object output = innerDataMap.get("output");
|
||||||
|
if (output != null) {
|
||||||
|
resultUrl = output.toString();
|
||||||
|
logger.info("从data.data.output提取到resultUrl: {}", resultUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 如果深层嵌套没有找到,检查当前层的output
|
||||||
|
if (resultUrl == null) {
|
||||||
|
Object output = nestedDataMap.get("output");
|
||||||
|
if (output != null) {
|
||||||
|
resultUrl = output.toString();
|
||||||
|
logger.info("从data.output提取到resultUrl: {}", resultUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 检查直接的resultUrl字段(旧格式)
|
||||||
|
if (resultUrl == null) {
|
||||||
|
Object resultUrlObj = taskData.get("resultUrl");
|
||||||
|
if (resultUrlObj != null) {
|
||||||
|
resultUrl = resultUrlObj.toString();
|
||||||
|
logger.info("从resultUrl字段提取到resultUrl: {}", resultUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 检查output字段(另一种格式)
|
||||||
|
if (resultUrl == null) {
|
||||||
|
Object output = taskData.get("output");
|
||||||
|
if (output != null) {
|
||||||
|
resultUrl = output.toString();
|
||||||
|
logger.info("从output字段提取到resultUrl: {}", resultUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 检查其他可能的字段名
|
||||||
|
if (resultUrl == null) {
|
||||||
|
Object videoUrl = taskData.get("video_url");
|
||||||
|
if (videoUrl != null) {
|
||||||
|
resultUrl = videoUrl.toString();
|
||||||
|
logger.info("从video_url字段提取到resultUrl: {}", resultUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (resultUrl == null) {
|
||||||
|
Object url = taskData.get("url");
|
||||||
|
if (url != null) {
|
||||||
|
resultUrl = url.toString();
|
||||||
|
logger.info("从url字段提取到resultUrl: {}", resultUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (resultUrl == null) {
|
||||||
|
Object result = taskData.get("result");
|
||||||
|
if (result != null) {
|
||||||
|
resultUrl = result.toString();
|
||||||
|
logger.info("从result字段提取到resultUrl: {}", resultUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取错误消息 - 支持多种字段名
|
||||||
String errorMessage = (String) taskData.get("errorMessage");
|
String errorMessage = (String) taskData.get("errorMessage");
|
||||||
|
if (errorMessage == null) {
|
||||||
|
errorMessage = (String) taskData.get("fail_reason");
|
||||||
|
}
|
||||||
|
if (errorMessage == null) {
|
||||||
|
errorMessage = (String) taskData.get("error");
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("任务状态更新: taskId={}, status={}, resultUrl={}, errorMessage={}",
|
logger.info("任务状态更新: taskId={}, status={}, resultUrl={}, errorMessage={}",
|
||||||
taskQueue.getTaskId(), status, resultUrl, errorMessage);
|
taskQueue.getTaskId(), status, resultUrl, errorMessage);
|
||||||
|
|
||||||
// 更新任务状态
|
// 更新任务状态 - 支持多种状态值
|
||||||
if ("completed".equals(status) || "success".equals(status)) {
|
if ("COMPLETED".equals(status) || "SUCCESS".equals(status)) {
|
||||||
logger.info("任务完成: {}", taskQueue.getTaskId());
|
logger.info("任务完成: {}, resultUrl: {}", taskQueue.getTaskId(), resultUrl);
|
||||||
updateTaskAsCompleted(taskQueue, resultUrl);
|
updateTaskAsCompleted(taskQueue, resultUrl);
|
||||||
} else if ("failed".equals(status) || "error".equals(status)) {
|
} else if ("FAILED".equals(status) || "ERROR".equals(status)) {
|
||||||
logger.warn("任务失败: {}, 错误: {}", taskQueue.getTaskId(), errorMessage);
|
logger.warn("任务失败: {}, 错误: {}", taskQueue.getTaskId(), errorMessage);
|
||||||
updateTaskAsFailed(taskQueue, errorMessage);
|
updateTaskAsFailed(taskQueue, errorMessage);
|
||||||
} else {
|
} else {
|
||||||
logger.info("任务继续处理中: {}, 状态: {}", taskQueue.getTaskId(), status);
|
// IN_PROGRESS, PROCESSING, PENDING 等状态继续处理
|
||||||
|
logger.info("任务继续处理中: {}, 状态: {}, resultUrl: {}", taskQueue.getTaskId(), status, resultUrl);
|
||||||
|
// 即使任务还在处理中,如果有结果URL,也更新任务记录(用于显示进度)
|
||||||
|
if (resultUrl != null && !resultUrl.isEmpty()) {
|
||||||
|
logger.info("任务处理中但已有resultUrl,更新任务记录: {}", resultUrl);
|
||||||
|
updateOriginalTaskStatus(taskQueue, "PROCESSING", resultUrl, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn("无法解析任务数据: taskId={}", taskQueue.getTaskId());
|
logger.warn("无法解析任务数据: taskId={}, data类型: {}",
|
||||||
|
taskQueue.getTaskId(), data != null ? data.getClass().getName() : "null");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn("外部API响应格式异常: taskId={}, response={}",
|
logger.warn("外部API响应格式异常: taskId={}, response={}, hasData={}",
|
||||||
taskQueue.getTaskId(), statusResponse);
|
taskQueue.getTaskId(), statusResponse,
|
||||||
|
statusResponse != null && statusResponse.containsKey("data"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否超时
|
// 检查是否超时
|
||||||
@@ -437,6 +590,12 @@ public class TaskQueueService {
|
|||||||
*/
|
*/
|
||||||
private void updateTaskAsCompleted(TaskQueue taskQueue, String resultUrl) {
|
private void updateTaskAsCompleted(TaskQueue taskQueue, String resultUrl) {
|
||||||
try {
|
try {
|
||||||
|
if (resultUrl == null || resultUrl.isEmpty()) {
|
||||||
|
logger.warn("任务 {} 标记为完成,但resultUrl为空,可能无法正常显示视频", taskQueue.getTaskId());
|
||||||
|
} else {
|
||||||
|
logger.info("任务 {} 已完成,resultUrl: {}", taskQueue.getTaskId(), resultUrl);
|
||||||
|
}
|
||||||
|
|
||||||
taskQueue.updateStatus(TaskQueue.QueueStatus.COMPLETED);
|
taskQueue.updateStatus(TaskQueue.QueueStatus.COMPLETED);
|
||||||
taskQueueRepository.save(taskQueue);
|
taskQueueRepository.save(taskQueue);
|
||||||
|
|
||||||
@@ -446,15 +605,19 @@ public class TaskQueueService {
|
|||||||
// 更新原始任务状态
|
// 更新原始任务状态
|
||||||
updateOriginalTaskStatus(taskQueue, "COMPLETED", resultUrl, null);
|
updateOriginalTaskStatus(taskQueue, "COMPLETED", resultUrl, null);
|
||||||
|
|
||||||
logger.info("任务 {} 已完成", taskQueue.getTaskId());
|
logger.info("任务 {} 状态更新完成", taskQueue.getTaskId());
|
||||||
|
|
||||||
// 创建用户作品 - 在最后执行,避免影响主要流程
|
// 创建用户作品 - 在最后执行,避免影响主要流程
|
||||||
try {
|
if (resultUrl != null && !resultUrl.isEmpty()) {
|
||||||
UserWork work = userWorkService.createWorkFromTask(taskQueue.getTaskId(), resultUrl);
|
try {
|
||||||
logger.info("创建用户作品成功: {}, 任务ID: {}", work.getId(), taskQueue.getTaskId());
|
UserWork work = userWorkService.createWorkFromTask(taskQueue.getTaskId(), resultUrl);
|
||||||
} catch (Exception workException) {
|
logger.info("创建用户作品成功: {}, 任务ID: {}", work.getId(), taskQueue.getTaskId());
|
||||||
logger.error("创建用户作品失败: {}, 但不影响任务完成状态", taskQueue.getTaskId(), workException);
|
} catch (Exception workException) {
|
||||||
// 作品创建失败不影响任务完成状态
|
logger.error("创建用户作品失败: {}, 但不影响任务完成状态", taskQueue.getTaskId(), workException);
|
||||||
|
// 作品创建失败不影响任务完成状态
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.warn("resultUrl为空,跳过创建用户作品: {}", taskQueue.getTaskId());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -517,14 +680,26 @@ public class TaskQueueService {
|
|||||||
if (taskOpt.isPresent()) {
|
if (taskOpt.isPresent()) {
|
||||||
TextToVideoTask task = taskOpt.get();
|
TextToVideoTask task = taskOpt.get();
|
||||||
if ("COMPLETED".equals(status)) {
|
if ("COMPLETED".equals(status)) {
|
||||||
|
logger.info("更新文生视频任务为完成状态: taskId={}, resultUrl={}", taskQueue.getTaskId(), resultUrl);
|
||||||
task.setResultUrl(resultUrl);
|
task.setResultUrl(resultUrl);
|
||||||
task.updateStatus(TextToVideoTask.TaskStatus.COMPLETED);
|
task.updateStatus(TextToVideoTask.TaskStatus.COMPLETED);
|
||||||
task.updateProgress(100);
|
task.updateProgress(100);
|
||||||
|
textToVideoTaskRepository.save(task);
|
||||||
|
logger.info("文生视频任务resultUrl已更新: taskId={}, resultUrl={}", taskQueue.getTaskId(), task.getResultUrl());
|
||||||
} else if ("FAILED".equals(status) || "CANCELLED".equals(status)) {
|
} else if ("FAILED".equals(status) || "CANCELLED".equals(status)) {
|
||||||
|
logger.info("更新文生视频任务为失败状态: taskId={}, errorMessage={}", taskQueue.getTaskId(), errorMessage);
|
||||||
task.updateStatus(TextToVideoTask.TaskStatus.FAILED);
|
task.updateStatus(TextToVideoTask.TaskStatus.FAILED);
|
||||||
task.setErrorMessage(errorMessage);
|
task.setErrorMessage(errorMessage);
|
||||||
|
textToVideoTaskRepository.save(task);
|
||||||
|
} else if ("PROCESSING".equals(status)) {
|
||||||
|
// 处理中状态,更新resultUrl以显示进度
|
||||||
|
logger.info("更新文生视频任务处理中状态: taskId={}, resultUrl={}", taskQueue.getTaskId(), resultUrl);
|
||||||
|
if (resultUrl != null && !resultUrl.isEmpty()) {
|
||||||
|
task.setResultUrl(resultUrl);
|
||||||
|
textToVideoTaskRepository.save(task);
|
||||||
|
logger.info("文生视频任务resultUrl已更新(处理中): taskId={}, resultUrl={}", taskQueue.getTaskId(), resultUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
textToVideoTaskRepository.save(task);
|
|
||||||
logger.info("原始文生视频任务状态已更新: {} -> {}", taskQueue.getTaskId(), status);
|
logger.info("原始文生视频任务状态已更新: {} -> {}", taskQueue.getTaskId(), status);
|
||||||
} else {
|
} else {
|
||||||
logger.warn("找不到原始文生视频任务: {}", taskQueue.getTaskId());
|
logger.warn("找不到原始文生视频任务: {}", taskQueue.getTaskId());
|
||||||
@@ -534,14 +709,26 @@ public class TaskQueueService {
|
|||||||
if (taskOpt.isPresent()) {
|
if (taskOpt.isPresent()) {
|
||||||
ImageToVideoTask task = taskOpt.get();
|
ImageToVideoTask task = taskOpt.get();
|
||||||
if ("COMPLETED".equals(status)) {
|
if ("COMPLETED".equals(status)) {
|
||||||
|
logger.info("更新图生视频任务为完成状态: taskId={}, resultUrl={}", taskQueue.getTaskId(), resultUrl);
|
||||||
task.setResultUrl(resultUrl);
|
task.setResultUrl(resultUrl);
|
||||||
task.updateStatus(ImageToVideoTask.TaskStatus.COMPLETED);
|
task.updateStatus(ImageToVideoTask.TaskStatus.COMPLETED);
|
||||||
task.updateProgress(100);
|
task.updateProgress(100);
|
||||||
|
imageToVideoTaskRepository.save(task);
|
||||||
|
logger.info("图生视频任务resultUrl已更新: taskId={}, resultUrl={}", taskQueue.getTaskId(), task.getResultUrl());
|
||||||
} else if ("FAILED".equals(status) || "CANCELLED".equals(status)) {
|
} else if ("FAILED".equals(status) || "CANCELLED".equals(status)) {
|
||||||
|
logger.info("更新图生视频任务为失败状态: taskId={}, errorMessage={}", taskQueue.getTaskId(), errorMessage);
|
||||||
task.updateStatus(ImageToVideoTask.TaskStatus.FAILED);
|
task.updateStatus(ImageToVideoTask.TaskStatus.FAILED);
|
||||||
task.setErrorMessage(errorMessage);
|
task.setErrorMessage(errorMessage);
|
||||||
|
imageToVideoTaskRepository.save(task);
|
||||||
|
} else if ("PROCESSING".equals(status)) {
|
||||||
|
// 处理中状态,更新resultUrl以显示进度
|
||||||
|
logger.info("更新图生视频任务处理中状态: taskId={}, resultUrl={}", taskQueue.getTaskId(), resultUrl);
|
||||||
|
if (resultUrl != null && !resultUrl.isEmpty()) {
|
||||||
|
task.setResultUrl(resultUrl);
|
||||||
|
imageToVideoTaskRepository.save(task);
|
||||||
|
logger.info("图生视频任务resultUrl已更新(处理中): taskId={}, resultUrl={}", taskQueue.getTaskId(), resultUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
imageToVideoTaskRepository.save(task);
|
|
||||||
logger.info("原始图生视频任务状态已更新: {} -> {}", taskQueue.getTaskId(), status);
|
logger.info("原始图生视频任务状态已更新: {} -> {}", taskQueue.getTaskId(), status);
|
||||||
} else {
|
} else {
|
||||||
logger.warn("找不到原始图生视频任务: {}", taskQueue.getTaskId());
|
logger.warn("找不到原始图生视频任务: {}", taskQueue.getTaskId());
|
||||||
|
|||||||
@@ -113,6 +113,11 @@ public class UserService {
|
|||||||
return userRepository.findByEmail(email).orElse(null);
|
return userRepository.findByEmail(email).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public User findByEmailOrNull(String email) {
|
||||||
|
return userRepository.findByEmail(email).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据手机号查找用户
|
* 根据手机号查找用户
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ tencent.ses.template-id=154360
|
|||||||
# AI API配置
|
# AI API配置
|
||||||
# 文生视频、图生视频、分镜视频都使用Comfly API
|
# 文生视频、图生视频、分镜视频都使用Comfly API
|
||||||
ai.api.base-url=https://ai.comfly.chat
|
ai.api.base-url=https://ai.comfly.chat
|
||||||
ai.api.key=sk-jp1O4h5lfN3WWZReF48SDa2osm0o9alC9qetkgq3M7XUjJ4R
|
ai.api.key=sk-xCX1X12e8Dpj4mRJKFMxFUnV29pzJQpPeuZFGqTwYOorjvOQ
|
||||||
# 文生图使用Comfly API (在代码中单独配置)
|
# 文生图使用Comfly API (在代码中单独配置)
|
||||||
ai.image.api.base-url=https://ai.comfly.chat
|
ai.image.api.base-url=https://ai.comfly.chat
|
||||||
ai.image.api.key=sk-jp1O4h5lfN3WWZReF48SDa2osm0o9alC9qetkgq3M7XUjJ4R
|
ai.image.api.key=sk-xCX1X12e8Dpj4mRJKFMxFUnV29pzJQpPeuZFGqTwYOorjvOQ
|
||||||
|
|
||||||
# 支付宝配置 (开发环境 - 沙箱测试)
|
# 支付宝配置 (开发环境 - 沙箱测试)
|
||||||
# 请替换为您的实际配置
|
# 请替换为您的实际配置
|
||||||
|
|||||||
@@ -30,3 +30,6 @@ CREATE TABLE IF NOT EXISTS task_queue (
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,3 +29,6 @@ CREATE TABLE IF NOT EXISTS points_freeze_records (
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,3 +32,6 @@ CREATE TABLE task_status (
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -574,6 +574,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -490,6 +490,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -529,6 +529,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
36
demo/start-frpc.bat
Normal file
36
demo/start-frpc.bat
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001 >nul
|
||||||
|
echo ====================================
|
||||||
|
echo 启动 FRP 客户端
|
||||||
|
echo ====================================
|
||||||
|
echo.
|
||||||
|
|
||||||
|
REM 检查 frpc.ini 是否存在
|
||||||
|
if not exist "frpc.ini" (
|
||||||
|
echo [错误] frpc.ini 配置文件不存在!
|
||||||
|
echo 请先创建 frpc.ini 配置文件
|
||||||
|
echo 可以参考 frpc.ini.example 文件
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
REM 检查 frpc.exe 是否存在
|
||||||
|
if not exist "frpc.exe" (
|
||||||
|
echo [错误] frpc.exe 不存在!
|
||||||
|
echo 请先下载 FRP 客户端:
|
||||||
|
echo https://github.com/fatedier/frp/releases
|
||||||
|
echo 解压后,将 frpc.exe 放在当前目录
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
echo 正在启动 FRP 客户端...
|
||||||
|
echo 配置文件: frpc.ini
|
||||||
|
echo.
|
||||||
|
|
||||||
|
REM 启动 FRP 客户端
|
||||||
|
frpc.exe -c frpc.ini
|
||||||
|
|
||||||
|
pause
|
||||||
|
|
||||||
|
|
||||||
@@ -33,3 +33,6 @@ pause > nul
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -60,3 +60,6 @@ public class TestApiConnection {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,3 +19,6 @@ except Exception as e:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,3 +27,6 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -63,3 +63,6 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
27
demo/update_database_schema.sql
Normal file
27
demo/update_database_schema.sql
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
-- 更新数据库表结构,将相关URL字段改为TEXT类型
|
||||||
|
-- 执行前请先备份数据库!
|
||||||
|
|
||||||
|
USE aigc_platform;
|
||||||
|
|
||||||
|
-- 更新 storyboard_video_tasks 表
|
||||||
|
ALTER TABLE storyboard_video_tasks
|
||||||
|
MODIFY COLUMN result_url TEXT,
|
||||||
|
MODIFY COLUMN image_url TEXT;
|
||||||
|
|
||||||
|
-- 更新 text_to_video_tasks 表
|
||||||
|
ALTER TABLE text_to_video_tasks
|
||||||
|
MODIFY COLUMN result_url TEXT;
|
||||||
|
|
||||||
|
-- 更新 image_to_video_tasks 表
|
||||||
|
ALTER TABLE image_to_video_tasks
|
||||||
|
MODIFY COLUMN result_url TEXT;
|
||||||
|
|
||||||
|
-- 更新 user_works 表
|
||||||
|
ALTER TABLE user_works
|
||||||
|
MODIFY COLUMN result_url TEXT,
|
||||||
|
MODIFY COLUMN thumbnail_url TEXT;
|
||||||
|
|
||||||
|
-- 更新 users 表
|
||||||
|
ALTER TABLE users
|
||||||
|
MODIFY COLUMN avatar TEXT;
|
||||||
|
|
||||||
Reference in New Issue
Block a user