main
HuangHai 2 months ago
parent f4b0b48033
commit 5df7ef5769

@ -0,0 +1,101 @@
package com.dsideal.aiSupport.Util.Liblib;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.aiSupport.Util.Liblib.Kit.LibLibCommon;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
/**
* LibLib API
*/
public class QueryModelVersion extends LibLibCommon {
// 日志
private static final Logger log = LoggerFactory.getLogger(QueryModelVersion.class);
// 查询模型版本API路径
private static final String MODEL_VERSION_PATH = "/api/model/version/get";
/**
*
*
* @param versionUuid UUID
* @return
* @throws IOException
*/
public static JSONObject queryModelVersion(String versionUuid) throws IOException {
// 创建OkHttpClient
OkHttpClient client = createHttpClient();
// 构建请求体
JSONObject requestBody = new JSONObject();
requestBody.put("versionUuid", versionUuid);
// 获取API路径
String uri = MODEL_VERSION_PATH;
// 生成签名信息
SignatureInfo signInfo = LibLibCommon.sign(uri);
// 构建带签名的URL
HttpUrl.Builder urlBuilder = HttpUrl.parse(API_BASE_URL + uri).newBuilder()
.addQueryParameter("AccessKey", accessKey)
.addQueryParameter("Signature", signInfo.getSignature())
.addQueryParameter("Timestamp", String.valueOf(signInfo.getTimestamp()))
.addQueryParameter("SignatureNonce", signInfo.getSignatureNonce());
// 创建请求
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, requestBody.toJSONString());
Request request = new Request.Builder()
.url(urlBuilder.build())
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
// 执行请求
log.info("查询模型版本信息: {}", requestBody.toJSONString());
Response response = client.newCall(request).execute();
// 处理响应
if (!response.isSuccessful()) {
String errorMsg = "查询模型版本信息失败,状态码: " + response.code();
log.error(errorMsg);
throw new IOException(errorMsg);
}
// 解析响应
String responseBody = response.body().string();
log.info("查询模型版本信息响应: {}", responseBody);
JSONObject responseJson = JSON.parseObject(responseBody);
int code = responseJson.getIntValue("code");
if (code != 0) {
String errorMsg = "查询模型版本信息失败,错误码: " + code + ", 错误信息: " + responseJson.getString("msg");
log.error(errorMsg);
throw new IOException(errorMsg);
}
return responseJson.getJSONObject("data");
}
/**
* 使
*/
public static void main(String[] args) {
try {
// 模型版本UUID
String versionUuid = "21df5d84cca74f7a885ba672b5a80d19";
// 查询模型版本信息
JSONObject modelInfo = queryModelVersion(versionUuid);
log.info("模型信息: {}", modelInfo.toJSONString());
} catch (Exception e) {
log.error("查询模型版本信息失败", e);
}
}
}
Loading…
Cancel
Save