main
HuangHai 2 months ago
parent d17721aa7e
commit 6d9b0f79fa

@ -26,18 +26,6 @@ public class KlText2Video extends KlCommon {
private static final String GENERATION_PATH = "/v1/videos/text2video";
private static final String QUERY_PATH = "/v1/videos/text2video/";
/**
*
*
* @param prompt
* @param modelName kling-v1, kling-v1-6
* @return ID
* @throws Exception
*/
public static String generateVideo(String prompt, String modelName) throws Exception {
return generateVideo(prompt, modelName, null);
}
/**
*
*
@ -142,54 +130,14 @@ public class KlText2Video extends KlCommon {
return responseJson;
}
/**
* ID
*
* @param externalTaskId ID
* @return
* @throws Exception
*/
public static JSONObject queryTaskStatusByExternalId(String externalTaskId) throws Exception {
// 获取JWT令牌
String jwt = KeLingJwtUtil.getJwt();
// 使用Hutool发送GET请求
HttpResponse response = HttpRequest.get(BASE_URL + GENERATION_PATH + "?external_task_id=" + externalTaskId)
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + jwt)
.execute();
// 检查响应状态码
if (response.getStatus() != 200) {
throw new Exception("请求失败,状态码:" + response.getStatus());
}
// 解析响应
String responseBody = response.body();
JSONObject responseJson = JSONUtil.parseObj(responseBody);
log.info("查询任务状态响应:{}", responseBody);
// 检查响应状态
int code = responseJson.getInt("code");
if (code != 0) {
String message = responseJson.getStr("message");
String solution = KlErrorCode.getSolutionByCode(code);
String errorMsg = String.format("查询任务状态失败:[%d] %s - %s", code, message, solution);
throw new Exception(errorMsg);
}
return responseJson;
}
/**
* URL
*
* @param fileUrl URL
* @param saveFilePath
* @throws Exception
*/
public static void downloadFile(String fileUrl, String saveFilePath) throws Exception {
public static void downloadFile(String fileUrl, String saveFilePath) {
try {
// 使用Hutool下载文件
long fileSize = HttpUtil.downloadFile(fileUrl, FileUtil.file(saveFilePath));
@ -216,7 +164,7 @@ public class KlText2Video extends KlCommon {
String taskId = null;
boolean accountIssue = false;
while (generateRetryCount < maxGenerateRetries && !accountIssue) {
while (!accountIssue) {
try {
taskId = generateVideo(prompt, modelName, externalTaskId);
break;

Loading…
Cancel
Save