2025-10-27 10:46:49 +08:00
|
|
|
import kong.unirest.HttpResponse;
|
|
|
|
|
import kong.unirest.Unirest;
|
|
|
|
|
import kong.unirest.UnirestException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class TestApiConnection {
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
String apiBaseUrl = "http://116.62.4.26:8081";
|
|
|
|
|
String apiKey = "ak_5f13ec469e6047d5b8155c3cc91350e2";
|
|
|
|
|
|
|
|
|
|
System.out.println("测试API连接...");
|
|
|
|
|
System.out.println("API端点: " + apiBaseUrl);
|
|
|
|
|
System.out.println("API密钥: " + apiKey.substring(0, 10) + "...");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 测试获取模型列表
|
|
|
|
|
System.out.println("\n1. 测试获取模型列表...");
|
|
|
|
|
HttpResponse<String> modelsResponse = Unirest.get(apiBaseUrl + "/user/ai/models")
|
|
|
|
|
.header("Authorization", "Bearer " + apiKey)
|
|
|
|
|
.asString();
|
|
|
|
|
|
|
|
|
|
System.out.println("状态码: " + modelsResponse.getStatus());
|
|
|
|
|
System.out.println("响应内容: " + modelsResponse.getBody());
|
|
|
|
|
|
|
|
|
|
// 测试提交任务
|
|
|
|
|
System.out.println("\n2. 测试提交文生视频任务...");
|
|
|
|
|
String requestBody = "{\n" +
|
|
|
|
|
" \"modelName\": \"sc_sora2_text_landscape_10s_small\",\n" +
|
|
|
|
|
" \"prompt\": \"一只猫在飞\",\n" +
|
|
|
|
|
" \"aspectRatio\": \"16:9\",\n" +
|
|
|
|
|
" \"imageToVideo\": false\n" +
|
|
|
|
|
"}";
|
|
|
|
|
|
|
|
|
|
HttpResponse<String> submitResponse = Unirest.post(apiBaseUrl + "/user/ai/tasks/submit")
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.header("Authorization", "Bearer " + apiKey)
|
|
|
|
|
.body(requestBody)
|
|
|
|
|
.asString();
|
|
|
|
|
|
|
|
|
|
System.out.println("状态码: " + submitResponse.getStatus());
|
|
|
|
|
System.out.println("响应内容: " + submitResponse.getBody());
|
|
|
|
|
|
|
|
|
|
} catch (UnirestException e) {
|
|
|
|
|
System.err.println("API调用异常: " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println("其他异常: " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-10-29 10:16:03 +08:00
|
|
|
|
|
|
|
|
|
2025-11-03 10:55:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-04 11:06:08 +08:00
|
|
|
|
2025-11-04 18:18:49 +08:00
|
|
|
|