头像视频合成

This commit is contained in:
spllzh
2025-10-08 08:02:21 +08:00
parent 76dedb657a
commit 45d061bad7
28 changed files with 689 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
package com.rj.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rj.dto.VideoSynthesisRequestDto;
import com.rj.entity.VideoSynthesisLog;
import com.rj.mapper.VideoSynthesisLogMapper;
@@ -59,7 +61,7 @@ public class VideoSynthesisServiceImpl implements IVideoSynthesisService {
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("X-DashScope-Async", "enable");
headers.set("Authorization", "Bearer " + apiKey);
request.buildParam();
// 构建请求体
HttpEntity<VideoSynthesisRequestDto> entity = new HttpEntity<>(request, headers);
@@ -76,14 +78,33 @@ public class VideoSynthesisServiceImpl implements IVideoSynthesisService {
String responseBody = response.getBody();
log.info("API响应: {}", responseBody);
// 简单解析关键字段
if (responseBody != null && responseBody.contains("task_id")) {
// 这里可以添加更复杂的JSON解析逻辑
// 暂时设置基本状态
synthesisLog.setTaskStatus("PENDING");
synthesisLog.setSuccess(true);
// 解析JSON响应
if (responseBody != null && !responseBody.trim().isEmpty()) {
try {
// 使用fastjson解析JSON响应
JSONObject responseJson = JSON.parseObject(responseBody);
// 提取task_id
if (responseJson.containsKey("output")) {
JSONObject output = responseJson.getJSONObject("output");
if (output != null && output.containsKey("task_id")) {
String taskId = output.getString("task_id");
synthesisLog.setTaskId(taskId);
log.info("提取到任务ID: {}", taskId);
}
}
// 设置基本状态
synthesisLog.setTaskStatus("PENDING");
synthesisLog.setSuccess(true);
} catch (Exception e) {
log.error("解析API响应JSON失败: {}", e.getMessage(), e);
synthesisLog.setErrorMessage("解析API响应失败: " + e.getMessage());
synthesisLog.setSuccess(false);
}
} else {
synthesisLog.setErrorMessage("API响应格式异常");
synthesisLog.setErrorMessage("API响应为空");
synthesisLog.setSuccess(false);
}