main
HuangHai 2 months ago
parent bc1f493674
commit 16eb444c87

@ -1,5 +1,7 @@
package com.dsideal.aiSupport.Util.JiMeng;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.aiSupport.Plugin.YamlProp;
import com.google.common.io.ByteStreams;
import com.jfinal.kit.Prop;
@ -265,4 +267,20 @@ public class JmCommon {
byte[] kService = hmacSHA256(kRegion, service);
return hmacSHA256(kService, "request");
}
/**
*
*
* @param taskId ID
*/
public static JSONObject queryTaskResult(String taskId) throws Exception {
String req_key = "jimeng_vgfm_t2v_l20";
String action = "CVSync2AsyncGetResult";
// 创建请求体
JSONObject req = new JSONObject();
req.put("task_id", taskId);
req.put("req_key", req_key);
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), action);
return JSON.parseObject(responseBody);
}
}

@ -1,34 +0,0 @@
package com.dsideal.aiSupport.Util.JiMeng;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
public class JmQueryTask extends JmCommon {
private static final Logger log = LoggerFactory.getLogger(JmQueryTask.class);
private static final String req_key = "jimeng_vgfm_t2v_l20";
private static final String action = "CVSync2AsyncGetResult";
/**
*
*
* @param taskId ID
*/
public static JSONObject queryTaskResult(String taskId) throws Exception {
// 创建请求体
JSONObject req = new JSONObject();
req.put("task_id", taskId);
req.put("req_key", req_key);
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), action);
return JSON.parseObject(responseBody);
}
public static void main(String[] args) throws Exception {
String taskId = "17796623341273230793";
JSONObject result = JmQueryTask.queryTaskResult(taskId);
System.out.println("查询结果: " + result);
}
}

@ -30,6 +30,24 @@ public class JmText2Video extends JmCommon {
public static void main(String[] args) throws Exception {
String prompt = "蓝色毛绒玩具在超市里拖地,结果拖把洒出好多五颜六色的粉末,接着把粉末洒向镜头前,镜头随之穿过粉末";
JSONObject jo = JmText2Video.generateVideo(prompt);
System.out.println(jo);
String taskId = jo.getJSONObject("data").getString("task_id");
//检查任务是不是已经结束
while (true) {
JSONObject result = JmCommon.queryTaskResult(taskId);
if (result.getInteger("code") != 10000) {
log.error("查询失败,错误代码=" + result.getInteger("code"));
break;
}
JSONObject data = result.getJSONObject("data");
String status = data.getString("status");
if (status.equals("done")) {
String video_url = data.getString("video_url");
log.info("视频地址:{}", video_url);
break;
} else {
log.info("任务处理中...");
Thread.sleep(5000);
}
}
}
}

Loading…
Cancel
Save