Commit f54d9f5f authored by wdy's avatar wdy

连接科恩接口

parent 6b689fcf
package com.ruoyi;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.domain.vo.UseCaseUrlVO;
import okhttp3.*;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.IOException;
import java.util.List;
@SpringBootTest
public class TestUrlK {
@Test
public void test() throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
// 定义查询变量
String variables = "{\n" +
" \"regulationName\":\"汽车整车信息安全技术要求\",\n" +
" \"matchUseCases\": [\"7.1.1.1-1\", \"7.2.11-3\"]\n" +
"}";
RequestBody body = RequestBody.create(mediaType, "{\"query\":\"query regulationItemsByUseCase($regulationName:String!$matchUseCases:[String!]!){regulationByName(name:$regulationName){itemsByUseCase(match:$matchUseCases){id serialNumber requirements useCases{id displayID customizedID class name description remediation requirements riskLevel method{name}scenario{name}}}}}\",\"variables\":"+variables+"}");
Request requestKs = new Request.Builder()
.url("http://10.12.48.80:8089/api/query")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjAsInRva2VuaWQiOjYxLCJ0eXBlIjoiYXBpIiwidXNlcm5hbWUiOiJhZG1pbiJ9.48Ggjx-FtOcecf73vAHn0XglwgLXZlfXxhXiLDHWWQE")
.build();
Response response = client.newCall(requestKs).execute();
String string = response.body().string();
JSONObject jsonObject = JSONObject.parseObject(string);
System.out.println("jsonObject = " + jsonObject);
// List<UseCaseUrlVO> list = jsonObject.getJSONObject("data").getJSONObject("useCases").getList("nodes", UseCaseUrlVO.class);
// list.forEach(item -> {
// System.out.println("item = " + item);
// });
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment