diff --git a/pom.xml b/pom.xml index 02bf02e..662483d 100644 --- a/pom.xml +++ b/pom.xml @@ -123,12 +123,16 @@ + + + + + - com.alibaba - fastjson - 1.2.83 + com.alibaba.fastjson2 + fastjson2 + 2.0.43 - io.springfox @@ -137,6 +141,12 @@ + com.squareup.okhttp3 + okhttp + 4.12.0 + + + io.springfox springfox-swagger2 2.4.0 diff --git a/src/main/java/com/fkzy/warn/common/conf/WebInterceptor.java b/src/main/java/com/fkzy/warn/common/conf/WebInterceptor.java index 88b0bed..4354fe1 100644 --- a/src/main/java/com/fkzy/warn/common/conf/WebInterceptor.java +++ b/src/main/java/com/fkzy/warn/common/conf/WebInterceptor.java @@ -1,7 +1,7 @@ package com.fkzy.warn.common.conf; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.common.constants.RedisKeyConstants; import com.fkzy.warn.common.constants.ResponseMsgConstants; import com.fkzy.warn.common.response.ApiResponse; diff --git a/src/main/java/com/fkzy/warn/common/constants/LawResearchUrlConstants.java b/src/main/java/com/fkzy/warn/common/constants/LawResearchUrlConstants.java index ace43bd..3b63193 100644 --- a/src/main/java/com/fkzy/warn/common/constants/LawResearchUrlConstants.java +++ b/src/main/java/com/fkzy/warn/common/constants/LawResearchUrlConstants.java @@ -23,6 +23,16 @@ public class LawResearchUrlConstants { // public final static String TICKET = "sWLi80ouoxiK9jYJFti2jz9KWnUtRvdepXf4jOWAwgyfSy4Kkf+n6yux/IuhFrL/"; + + public final static String APPID = "ea255f4a400342b5b96c8fb904616354"; + public final static String API_KEY = "956ee3a3106ba289ce87d46f877b78ef"; + public final static String API_SECRET = "b2f77e1395324dcbd1557d4a2908c9fd"; + public final static String ACCESS_KEY = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJidXNpbmVzc1N5c3RlbUlkIjoiMTkyNzI1MzAzNjM5MjUzODExNCIsImFwcEtleSI6Ijk1NmVlM2EzMTA2YmEyODljZTg3ZDQ2Zjg3N2I3OGVmIiwiYXBwSWQiOiJlYTI1NWY0YTQwMDM0MmI1Yjk2YzhmYjkwNDYxNjM1NCIsInB1YmxpY0tleSI6IjgwMzRkODcxMzJkZjIyYjQwOGQzZTFhYmIwYmEyM2E4IiwiaXNzIjoiY29wIiwic3ViIjoi5oiR55qE6buY6K6k5bqU55SoIiwiYXVkIjoiMTE4LjExMy4xMTcuMjI4IiwiZXhwIjoxNzczOTkzNTg1LCJuYmYiOjE3NzM3MzQzODUsImlhdCI6MTc3MzczNDM4NSwianRpIjoiMTE2YmY1ZDJmYjAzNGQwMDlmYjhlN2Y1NDkzOWE1NDUifQ.26xvUO1ELQ8RqRFk-jyjo5HFhQrSjVpcSozx5xG4zCs"; + + + + + //司法 public final static String QUERY_SSSXXG = "/qyss/sfss/querySssxxg"; //-------------------------------新接口-------------------- diff --git a/src/main/java/com/fkzy/warn/common/request/RequestParameter.java b/src/main/java/com/fkzy/warn/common/request/RequestParameter.java index a5fb1a3..830f37d 100644 --- a/src/main/java/com/fkzy/warn/common/request/RequestParameter.java +++ b/src/main/java/com/fkzy/warn/common/request/RequestParameter.java @@ -1,6 +1,7 @@ package com.fkzy.warn.common.request; -import com.alibaba.fastjson.JSONObject; + +import com.alibaba.fastjson2.JSONObject; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/java/com/fkzy/warn/common/util/Demo.java b/src/main/java/com/fkzy/warn/common/util/Demo.java index 69fc990..8a35718 100644 --- a/src/main/java/com/fkzy/warn/common/util/Demo.java +++ b/src/main/java/com/fkzy/warn/common/util/Demo.java @@ -1,9 +1,9 @@ package com.fkzy.warn.common.util; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONException; -import com.alibaba.fastjson.JSONObject; + +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONException; +import com.alibaba.fastjson2.JSONObject; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.IgnoredErrorType; @@ -25,8 +25,8 @@ public class Demo { LawResearchUtil law = new LawResearchUtil(); // law.querySxx(null, null); // law.queryDishonest(null, null,null,null); - law.queryLimitConsumption(null, null,null,null); -// law.monitorQuery(null, null); +// law.queryLimitConsumption(null, null,null,null); + law.monitorQuery(null, null); // law.delcompany(null); // law.queryMonitorCases(null,null,null); // law.addpublic(null); diff --git a/src/main/java/com/fkzy/warn/common/util/FyOpenGatewayApiUtil.java b/src/main/java/com/fkzy/warn/common/util/FyOpenGatewayApiUtil.java new file mode 100644 index 0000000..58b9b29 --- /dev/null +++ b/src/main/java/com/fkzy/warn/common/util/FyOpenGatewayApiUtil.java @@ -0,0 +1,226 @@ +package com.fkzy.warn.common.util; + + +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.fkzy.warn.common.constants.LawResearchUrlConstants; +import com.fkzy.warn.model.InvocationRecord; +import org.springframework.http.*; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * @author zhangjing + * @date 2026/03/17 14:31 + * @description + */ +public class FyOpenGatewayApiUtil { + public static final String FY_OPEN_GATEWAY_URL = "https://api.cjbdi.com:8443"; + + public static final String ACCESS_TOKEN_URL = FY_OPEN_GATEWAY_URL + "/auth/api/token/getAccess"; + + /** + * 请求开放平台网关获取accessToken + * + * @param url 调用地址 + * @param appKey 应用key--从控制台应用系统中获取 + * @param appSecret 应用密码--从控制台应用系统中获取 + * @return 返回数据格式参考在线文档说明 + */ + public static String getAccessToken(String url, String appKey, String appSecret) { + Map paramMap = new HashMap<>(); + paramMap.put("appKey", appKey); + paramMap.put("appSecret", appSecret); + try { + return HttpUtil.post(url, paramMap); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +// /** +// * 接口调用--url传参 +// * +// * @param method 请求方法类型 +// * @param url 接口地址,包含url参数 +// * @param headerMap 请求头 +// * @return 返回数据格式参考在线文档说明 +// * @see cn.hutool.http.Method +// */ +// public static String invokeUrlApi(Method method, String url, Map headerMap) { +// HttpRequest request = HttpUtil.createRequest(method, url); +// request.headerMap(headerMap, true); +// try (HttpResponse execute = request.execute()) { +// int status = execute.getStatus(); +// if (status == 200) { +// return execute.body(); +// } +// } +// return null; +// } + +// /** +// * 接口调用--form表单提交 +// * +// * @param url 接口地址,包含url参数 +// * @param headerMap 请求头 +// * @param formParams form表单参数 +// * @return 返回数据格式参考在线文档说明 +// */ +// public static String invokeFormApi(String url, Map headerMap, Map formParams) { +// HttpRequest request = HttpUtil.createPost(url); +// request.headerMap(headerMap, true); +// request.form(formParams); +// try (HttpResponse execute = request.execute()) { +// int status = execute.getStatus(); +// if (status == 200) { +// return execute.body(); +// } +// } +// return null; +// } + +// /** +// * 接口调用--body提交 +// * +// * @param url 接口地址 +// * @param headerMap 请求头 +// * @param body body参数 +// * @return 返回数据格式参考在线文档说明 +// */ +// public static String invokeBodyApi(String url, Map headerMap, String body) { +// HttpRequest request = HttpUtil.createPost(url); +// request.headerMap(headerMap, true); +// request.body(body); +// try (HttpResponse execute = request.execute()) { +// int status = execute.getStatus(); +// if (status == 200) { +// return execute.body(); +// } +// } +// return null; +// } + + + public static void main(String[] args) { + // 控制台应用系统中的apiKey + String appKey = ""; + // 控制台应用系统中的apiSecret + String appSecret = ""; + // 控制台应用系统中的appId + String appId = ""; + + // 请求获取accessToken + String response = getAccessToken(ACCESS_TOKEN_URL, LawResearchUrlConstants.API_KEY, LawResearchUrlConstants.API_SECRET); + System.out.println(response); + + // 构建请求头 + Map headerMap = new HashMap<>(); + // 请求id,每次请求需重新生成,保证唯一。用于做重复请求验证 + headerMap.put("FYDN-OP-RequestId", UUID.randomUUID().toString().replaceAll("-", "")); + // 签名串,使用在线文档中的MD5Util示例加密生成 + headerMap.put("FYDN-OP-Sign", ""); + // 需要从getAccessToken返回结果中解析出accessKey,返回结构样例参考在线文档 + headerMap.put("FYDN-OP-AccessToken", LawResearchUrlConstants.ACCESS_KEY); + headerMap.put("FYDN-OP-AppID", LawResearchUrlConstants.APPID); + // 调用的环境(prod:线上环境,默认;test:测试环境) + headerMap.put("FYDN-OP-Env", "prod"); + // 用户所在系统的唯一标识 + headerMap.put("FYDN-OP-UserId", ""); + + // 以下url、参数等为示例,以实际调用的信息为准 + /*--------------------------------json传参-----------------------------------*/ +// String jsonApiUrl = "http://127.0.0.1:8080/jsonApi"; +// headerMap.put(Header.CONTENT_TYPE.getValue(), ContentType.JSON.getValue()); +// String body = "{\"name\":\"test\", \"age\":18}"; +// String jsonApiResult = FyOpenGatewayApiUtil.invokeBodyApi(jsonApiUrl, headerMap, body); +// System.out.println(jsonApiResult); + + +// +// /*--------------------------------form传参-----------------------------------*/ +// String formApiUrl = "http://127.0.0.1:8080/formApi"; +// // 普通form表单时,设置为application/x-www-form-urlencoded +// headerMap.put(Header.CONTENT_TYPE.getValue(), ContentType.FORM_URLENCODED.getValue()); +// // 文件上传form表单提交时,设置为multipart/form-data +//// headerMap.put(Header.CONTENT_TYPE.getValue(), ContentType.MULTIPART.getValue()); +// Map formParams = new HashMap<>(); +// formParams.put("name", "test"); +// formParams.put("age", 18); +// String formApiResult = FyOpenGatewayApiUtil.invokeFormApi(formApiUrl, headerMap, formParams); +// System.out.println(formApiResult); +// +// /*--------------------------------url传参-----------------------------------*/ +// String url = "http://127.0.0.1:8080/urlApi?name=test&age=18"; +// headerMap.put(Header.CONTENT_TYPE.getValue(), ContentType.FORM_URLENCODED.getValue()); +// String result = FyOpenGatewayApiUtil.invokeUrlApi(Method.GET, url, headerMap); +// System.out.println(result); + } + private static InvocationRecord getData(String apiUrl, JSONArray array, JSONObject jsonObject, String method, + String key, String ticket, String apiName + ) { + InvocationRecord invocationRecord = new InvocationRecord(); + invocationRecord.setApiKey(key); + invocationRecord.setApiTicket(ticket); + invocationRecord.setApiUrl(apiUrl); + if (array!=null){ + invocationRecord.setInputArr(array.toJSONString()); + } + if (jsonObject!=null){ + invocationRecord.setInputObj(jsonObject.toJSONString()); + } + invocationRecord.setApiName(apiName); + + RestTemplate restTemplate = new RestTemplate(); + HttpComponentsClientHttpRequestFactory requestFactory + = new HttpComponentsClientHttpRequestFactory(); + requestFactory.setConnectionRequestTimeout(60000); + requestFactory.setConnectTimeout(60000); + requestFactory.setReadTimeout(60000); + restTemplate.setRequestFactory(requestFactory); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("ticket", ticket); + headers.set("Authorization", ticket); + String request = (array != null) ? array.toJSONString() : jsonObject.toJSONString(); + try { + //需要对入参进行 aes 加密 + String requestBody = AES.aesEncrypt(request, key); + System.out.println("requestBody=====" + requestBody); + //设置访问的 Entity + HttpEntity entity = new HttpEntity<>(requestBody, headers); + //执行 请求 + + ResponseEntity result = + restTemplate.exchange(apiUrl, method == null ? HttpMethod.POST : HttpMethod.GET, entity, + String.class); + // 指定文件路径 + String filePath = "output.txt"; + String resultData=null; + try (PrintWriter writer = new PrintWriter(new File(filePath))) { + //接收到返回结果需要进行 aes 解密 + invocationRecord.setIsSuccess(0); + resultData = AES.aesDecrypt(result.getBody(), key); + //写入内容 + writer.println(resultData); + invocationRecord.setIsSuccess(1); + invocationRecord.setApiResult(resultData); + // 自动关闭,因为使用了 try-with-resources 语句 + } catch (FileNotFoundException e) { + System.err.println("文件未找到: " + e.getMessage()); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + return invocationRecord; + } + } +} diff --git a/src/main/java/com/fkzy/warn/common/util/HttpUtil.java b/src/main/java/com/fkzy/warn/common/util/HttpUtil.java index acc46c9..abc647d 100644 --- a/src/main/java/com/fkzy/warn/common/util/HttpUtil.java +++ b/src/main/java/com/fkzy/warn/common/util/HttpUtil.java @@ -1,6 +1,7 @@ package com.fkzy.warn.common.util; -import com.alibaba.fastjson.JSONObject; + +import com.alibaba.fastjson2.JSONObject; import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; import org.apache.http.StatusLine; @@ -19,6 +20,9 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Map; /** * http工具类 @@ -150,49 +154,39 @@ public class HttpUtil { return resultJson; } - public static String doPost(String url, String params) throws Exception { + public static String post(String apiUrl, Map paramMap) throws Exception { + // 将 paramMap 转为 JSON 字符串 - CloseableHttpClient httpclient = HttpClients.createDefault(); - HttpPost httpPost = new HttpPost(url);// 创建httpPost - httpPost.setHeader("Accept", "application/json"); - httpPost.setHeader("Content-Type", "application/json"); - RequestConfig defaultRequestConfig = RequestConfig.custom() - .setSocketTimeout(10000) - .setConnectTimeout(10000) - .setConnectionRequestTimeout(10000) - .build(); - httpPost.setConfig(defaultRequestConfig); - String charSet = "UTF-8"; - StringEntity entity = new StringEntity(params, charSet); - httpPost.setEntity(entity); - CloseableHttpResponse response = null; - HttpClientContext context = HttpClientContext.create(); - try { - response = httpclient.execute(httpPost, context); - StatusLine status = response.getStatusLine(); - int state = status.getStatusCode(); - if (state == HttpStatus.SC_OK) { - HttpEntity responseEntity = response.getEntity(); - String jsonString = EntityUtils.toString(responseEntity); - return jsonString; - } else { - //do log - } - } finally { - if (response != null) { - try { - response.close(); - } catch (IOException e) { - e.printStackTrace(); + + try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + HttpPost httpPost = new HttpPost(apiUrl); + + RequestConfig config = RequestConfig.custom() + .setSocketTimeout(10000) + .setConnectTimeout(10000) + .setConnectionRequestTimeout(10000) + .build(); + httpPost.setConfig(config); + + // 构造 x-www-form-urlencoded 参数 + String params = "appKey=" + URLEncoder.encode(paramMap.get("appKey"), StandardCharsets.UTF_8.toString()) + + "&appSecret=" + URLEncoder.encode(paramMap.get("appSecret"), StandardCharsets.UTF_8.toString()); + + StringEntity entity = new StringEntity(params, StandardCharsets.UTF_8); + httpPost.setEntity(entity); + httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); + + try (CloseableHttpResponse response = httpclient.execute(httpPost)) { + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode == 200) { + HttpEntity resEntity = response.getEntity(); + return EntityUtils.toString(resEntity, StandardCharsets.UTF_8); + } else { + System.err.println("HTTP Error: " + statusCode); + return null; } } - try { - httpclient.close(); - } catch (IOException e) { - e.printStackTrace(); - } } - return null; } } \ No newline at end of file diff --git a/src/main/java/com/fkzy/warn/common/util/JWTUtil.java b/src/main/java/com/fkzy/warn/common/util/JWTUtil.java index a1a6c0e..fd7605c 100644 --- a/src/main/java/com/fkzy/warn/common/util/JWTUtil.java +++ b/src/main/java/com/fkzy/warn/common/util/JWTUtil.java @@ -3,6 +3,7 @@ package com.fkzy.warn.common.util; //import com.lzrq.template.model.User; +import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.fkzy.warn.model.User; @@ -116,7 +117,7 @@ public class JWTUtil { Payload payload = jwsObject.getPayload(); JSONObject jsonObject = payload.toJSONObject(); String result = jsonObject.toString(); - user = com.alibaba.fastjson.JSONObject.parseObject(result, User.class); + user = JSON.parseObject(result, User.class); } catch (ParseException e) { e.printStackTrace(); diff --git a/src/main/java/com/fkzy/warn/common/util/LawResearchUtil.java b/src/main/java/com/fkzy/warn/common/util/LawResearchUtil.java index 22c7b0d..d128f56 100644 --- a/src/main/java/com/fkzy/warn/common/util/LawResearchUtil.java +++ b/src/main/java/com/fkzy/warn/common/util/LawResearchUtil.java @@ -1,7 +1,8 @@ package com.fkzy.warn.common.util; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; + +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.common.constants.EntityConstants; import com.fkzy.warn.common.constants.LawResearchUrlConstants; import com.fkzy.warn.model.InvocationRecord; @@ -76,8 +77,10 @@ public class LawResearchUtil { // creditCode = "91411728MA47Q0KJ5B"; // name = "北京图灵高斯科技服务有限公司"; // creditCode = "91110102MACPFACT41"; - name = "丰县城市建设投资集团有限公司"; - creditCode = "91320321687806130M"; +// name = "丰县城市建设投资集团有限公司"; +// creditCode = "91320321687806130M"; + name = "刘超"; + creditCode = "320122198410080037"; // name = "恒大集团有限公司"; // creditCode = "91440300087909371X"; } @@ -85,7 +88,8 @@ public class LawResearchUtil { JSONArray array = new JSONArray(); JSONObject jsonObject = new JSONObject(); jsonObject.put("name", name); - jsonObject.put("creditCode", creditCode); +// jsonObject.put("creditCode", creditCode); + jsonObject.put("id", creditCode); jsonObject.put("authorize", 1); array.add(jsonObject); return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.QUERY_SXX, @@ -741,7 +745,7 @@ public class LawResearchUtil { public InvocationRecord addpublic(String name) { //默认测试数据 if (name == null) { - name = "平凉市宏建煤炭有限责任公司"; + name = "丰县城市建设投资集团有限公司"; // creditCode = "91110108551385082Q"; } JSONObject jsonObject = new JSONObject(); diff --git a/src/main/java/com/fkzy/warn/common/util/MD5Util.java b/src/main/java/com/fkzy/warn/common/util/MD5Util.java new file mode 100644 index 0000000..d283890 --- /dev/null +++ b/src/main/java/com/fkzy/warn/common/util/MD5Util.java @@ -0,0 +1,180 @@ +package com.fkzy.warn.common.util; + +import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson2.JSONWriter; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Iterator; +import java.util.Objects; +import java.util.TreeMap; + +/** + * MD5工具类 + */ +@Slf4j +public class MD5Util { + + /** + * 生成签名串 + * + * @param params 升序的参数 + * @param slat 加盐:应用系统的apiKey,从控制台应用系统中获取 + * @return 16进制签名串 + */ + public static String md5Sign(String params, String slat) { + return digestToHex(params + slat); + } + + /** + * 验签 + * + * @param params 升序的参数 + * @param sign 签名串 + * @param slat 加盐:应用系统的apiKey,从控制台应用系统中获取 + * @return true 表示验签通过 + */ + public static boolean checkSign(String params, String sign, String slat) { + try { + String signData = digestToHex(params + slat); + log.info("生成的签名:{}", signData); + return StringUtils.equals(signData, sign); + } catch (Exception e) { + log.error("验签异常:", e); + return false; + } + } + + /** + * json参数排序
+ *

+ * post请求为json传参时,调用该方法,按json中的key升序排列 + *

+ * @param obj json参数 + * @return key升序的json字符串 + */ + public static String sortJsonToStr(Object obj) { + if (Objects.isNull(obj) || "".equals(obj)) { + return ""; + } + if (obj instanceof Integer + || obj instanceof Short + || obj instanceof Long + || obj instanceof Float + || obj instanceof Double + || obj instanceof Boolean + || obj instanceof Character + || obj instanceof Byte) { + return String.valueOf(obj); + } + if (obj instanceof String) { + return JSONObject.toJSONString(JSONObject.parseObject(String.valueOf(obj)), JSONWriter.Feature.MapSortField); + } + try { + return JSONObject.toJSONString(obj, JSONWriter.Feature.MapSortField); + } catch (Exception e) { + return String.valueOf(obj); + } + } + + /** + * url参数排序 + *
+ * 该方法适用范围: + *
    + *
  • get请求:url参数传参
  • + *
  • post请求:form-data传参
  • + *
+ *

+ * 比如: a=1&c=3&b=2 排序后 a=1&b=2&c=3 + *

+ * + * @param paraMap TreeMap类型,将参数都放入其中 + * @return 按顺序拼接好的参数串 + */ + public static String getUrlParamsSign(TreeMap paraMap, String slat) { + if (Objects.isNull(paraMap) || paraMap.isEmpty()) { + return md5Sign("", slat); + } + Iterator it = paraMap.keySet().iterator(); + StringBuilder paramStr = new StringBuilder(); + while (it.hasNext()) { + String key = it.next(); + Object o = paraMap.get(key); + if (Objects.isNull(o)) { + paramStr.append("&").append(key).append("="); + } else { + paramStr.append("&").append(key).append("=").append(o); + } + } + String urlParams = paramStr.substring(1); + return md5Sign(urlParams, slat); + } + + private static String digestToHex(String s) { + try { + MessageDigest digest = MessageDigest.getInstance("MD5"); + byte[] b = digest.digest(s.getBytes(StandardCharsets.UTF_8)); + return toHexString(b); + } catch (NoSuchAlgorithmException e) { + log.info("MD5异常,", e); + return null; + } + } + + private static final char[] HEX_CHARS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + + private static String toHexString(byte[] b) { + return b == null ? null : toHexString(b, 0, b.length); + } + + private static String toHexString(byte[] b, int offset, int length) { + if (b == null) { + return null; + } else { + int end = offset + length; + StringBuilder sb = new StringBuilder(length * 2); + for (int i = offset; i < end; ++i) { + int c = b[i] >> 4 & 15; + sb.append(HEX_CHARS[c]); + c = b[i] & 15; + sb.append(HEX_CHARS[c]); + } + return sb.toString(); + } + } + + public static void main(String[] args) { + // 签名的盐值,控制台应用系统中的apiKey + String apiKey = "123456"; + + // url传参方式签名 比如a=1&b=2&c=3 + TreeMap paramMap = new TreeMap<>(); + paramMap.put("a", 1); + paramMap.put("b", 2); + paramMap.put("c", 3); + String urlParamsSign = getUrlParamsSign(paramMap, apiKey); + System.out.println("url参数签名(getUrlParamsSign方法): " + urlParamsSign); + + String urlParamsSign2 = md5Sign("a=1&b=2&c=3", apiKey); + System.out.println("url参数签名(md5Sign方法): " + urlParamsSign2); + + // json传参方式签名 + String obj = "{\"a\":\"0\",\"c\":\"\",\"d\":0,\"b\":\"0\",\"c1\":\"\",\"a1\":\"0\"}"; + + String sortedJsonStr = sortJsonToStr(obj); + System.out.println("json字符串排序结果:" + sortedJsonStr); + String jsonStrSign = md5Sign(sortedJsonStr, apiKey); + System.out.println("json字符串签名结果:" + jsonStrSign); + + JSONObject jsonObject = JSONObject.parseObject(obj); + String sortedJsonStr2 = sortJsonToStr(jsonObject); + System.out.println("json对象排序结果:" + sortedJsonStr2); + String jsonSign = md5Sign(sortedJsonStr2, apiKey); + System.out.println("json对象签名结果:" + jsonSign); + + } +} \ No newline at end of file diff --git a/src/main/java/com/fkzy/warn/common/util/RedisUtil.java b/src/main/java/com/fkzy/warn/common/util/RedisUtil.java index f0481cd..622b468 100644 --- a/src/main/java/com/fkzy/warn/common/util/RedisUtil.java +++ b/src/main/java/com/fkzy/warn/common/util/RedisUtil.java @@ -1,8 +1,9 @@ package com.fkzy.warn.common.util; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.TypeReference; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.TypeReference; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/com/fkzy/warn/controller/AccountController.java b/src/main/java/com/fkzy/warn/controller/AccountController.java index c4ebe66..1acf8d6 100644 --- a/src/main/java/com/fkzy/warn/controller/AccountController.java +++ b/src/main/java/com/fkzy/warn/controller/AccountController.java @@ -1,6 +1,6 @@ package com.fkzy.warn.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.common.constants.ResponseMsgConstants; import com.fkzy.warn.common.request.RequestParameter; import com.fkzy.warn.model.User; diff --git a/src/main/java/com/fkzy/warn/controller/AnnouncementController.java b/src/main/java/com/fkzy/warn/controller/AnnouncementController.java index 2c7bb20..269ae66 100644 --- a/src/main/java/com/fkzy/warn/controller/AnnouncementController.java +++ b/src/main/java/com/fkzy/warn/controller/AnnouncementController.java @@ -1,6 +1,6 @@ package com.fkzy.warn.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.model.Announcement; import com.fkzy.warn.service.AnnouncementService; import com.fkzy.warn.common.constants.ResponseMsgConstants; diff --git a/src/main/java/com/fkzy/warn/controller/AuditRecordsController.java b/src/main/java/com/fkzy/warn/controller/AuditRecordsController.java index 90b81b3..a93f268 100644 --- a/src/main/java/com/fkzy/warn/controller/AuditRecordsController.java +++ b/src/main/java/com/fkzy/warn/controller/AuditRecordsController.java @@ -1,6 +1,6 @@ package com.fkzy.warn.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.common.constants.ResponseMsgConstants; import com.fkzy.warn.common.request.RequestParameter; import com.fkzy.warn.common.response.ApiResponse; diff --git a/src/main/java/com/fkzy/warn/controller/AuthorizationController.java b/src/main/java/com/fkzy/warn/controller/AuthorizationController.java index 18aa59f..019286e 100644 --- a/src/main/java/com/fkzy/warn/controller/AuthorizationController.java +++ b/src/main/java/com/fkzy/warn/controller/AuthorizationController.java @@ -1,6 +1,6 @@ package com.fkzy.warn.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.service.AuthorizationService; import com.fkzy.warn.common.constants.ResponseMsgConstants; import com.fkzy.warn.common.request.RequestParameter; diff --git a/src/main/java/com/fkzy/warn/controller/ContractController.java b/src/main/java/com/fkzy/warn/controller/ContractController.java index 9daccdb..3af3048 100644 --- a/src/main/java/com/fkzy/warn/controller/ContractController.java +++ b/src/main/java/com/fkzy/warn/controller/ContractController.java @@ -1,6 +1,6 @@ package com.fkzy.warn.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.common.constants.ResponseMsgConstants; import com.fkzy.warn.common.request.RequestParameter; import com.fkzy.warn.common.response.ApiResponse; diff --git a/src/main/java/com/fkzy/warn/controller/DataCenterController.java b/src/main/java/com/fkzy/warn/controller/DataCenterController.java index bd8641c..34de5f4 100644 --- a/src/main/java/com/fkzy/warn/controller/DataCenterController.java +++ b/src/main/java/com/fkzy/warn/controller/DataCenterController.java @@ -2,6 +2,10 @@ package com.fkzy.warn.controller; import com.fkzy.warn.common.constants.ResponseMsgConstants; import com.fkzy.warn.common.response.ApiResponse; +import com.fkzy.warn.model.AImessage; +import com.fkzy.warn.model.params.AILawParams; +import com.fkzy.warn.model.params.LawGroupParam; +import com.fkzy.warn.service.FyApiService; import com.fkzy.warn.service.LawCaseService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -12,6 +16,10 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; /** * @author zhangjing @@ -25,6 +33,8 @@ import javax.annotation.Resource; public class DataCenterController { @Resource private LawCaseService lawCaseService; + @Resource + private FyApiService fyApiService; @RequestMapping(value = "judicialModelSave", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiOperation(value = "司法模型") @@ -40,4 +50,41 @@ public class DataCenterController { return apiResponse; } + @RequestMapping(value = "getLawGroup", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + @ApiOperation(value = "法律法规分组列表") + public ApiResponse getLawGroup() { + ApiResponse apiResponse = new ApiResponse(); + try { + LawGroupParam lawGroupParam = new LawGroupParam(); + lawGroupParam.setOrgan("全国人民代表大会"); + lawGroupParam.setExprityDateList(Collections.singletonList("[全国人民代表大会]")); + lawGroupParam.setSourceList(Collections.singletonList("[地方政府规章]")); + lawGroupParam.setTimeliness("现行有效"); + lawGroupParam.setPageSize(20); + lawGroupParam.setPubDate("2014"); + lawGroupParam.setPubDateList(Collections.singletonList("[地方政府规章]")); + lawGroupParam.setTimelinessList(Collections.singletonList("[现行有效]")); + lawGroupParam.setTitle("中国"); + lawGroupParam.setPageNum(1); + +// fyApiService.getLawGroup(lawGroupParam); +// fyApiService.getLawGroupInfo("9f9d4094-d788-52f6-804d-0fc2a5dd462f"); + AILawParams aiLawParams = new AILawParams(); + aiLawParams.setStream(true); + aiLawParams.setModel("中国法研LLM"); + AImessage aImessage = new AImessage(); + aImessage.setContent("借条和欠条的区别"); + aImessage.setRole("user"); + List aImessageList = new ArrayList<>(); + aImessageList.add(aImessage); + aiLawParams.setMessages(aImessageList); + fyApiService.sendAILaw(aiLawParams); + } catch (Exception e) { + log.error("查询错误,errMsg==={}", e.getMessage()); + e.printStackTrace(); + apiResponse.recordError(ResponseMsgConstants.OPERATE_FAIL); + } + return apiResponse; + } + } diff --git a/src/main/java/com/fkzy/warn/controller/MonitorUsersController.java b/src/main/java/com/fkzy/warn/controller/MonitorUsersController.java index 7a237ef..34629c1 100644 --- a/src/main/java/com/fkzy/warn/controller/MonitorUsersController.java +++ b/src/main/java/com/fkzy/warn/controller/MonitorUsersController.java @@ -1,6 +1,6 @@ package com.fkzy.warn.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.common.constants.ResponseMsgConstants; import com.fkzy.warn.common.request.RequestParameter; import com.fkzy.warn.common.response.ApiResponse; diff --git a/src/main/java/com/fkzy/warn/controller/NewsManageController.java b/src/main/java/com/fkzy/warn/controller/NewsManageController.java index e6616cc..944aa9f 100644 --- a/src/main/java/com/fkzy/warn/controller/NewsManageController.java +++ b/src/main/java/com/fkzy/warn/controller/NewsManageController.java @@ -1,6 +1,6 @@ package com.fkzy.warn.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.common.constants.ResponseMsgConstants; import com.fkzy.warn.common.request.RequestParameter; import com.fkzy.warn.common.response.ApiResponse; diff --git a/src/main/java/com/fkzy/warn/controller/PermissionController.java b/src/main/java/com/fkzy/warn/controller/PermissionController.java index 6ab0a7e..9d73983 100644 --- a/src/main/java/com/fkzy/warn/controller/PermissionController.java +++ b/src/main/java/com/fkzy/warn/controller/PermissionController.java @@ -1,6 +1,6 @@ package com.fkzy.warn.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.model.Permission; import com.fkzy.warn.service.PermissionService; import com.fkzy.warn.common.constants.ResponseMsgConstants; diff --git a/src/main/java/com/fkzy/warn/controller/PolicyManagementController.java b/src/main/java/com/fkzy/warn/controller/PolicyManagementController.java index cc7a9ae..fb23a1e 100644 --- a/src/main/java/com/fkzy/warn/controller/PolicyManagementController.java +++ b/src/main/java/com/fkzy/warn/controller/PolicyManagementController.java @@ -1,6 +1,6 @@ package com.fkzy.warn.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.common.constants.ResponseMsgConstants; import com.fkzy.warn.common.request.RequestParameter; import com.fkzy.warn.common.response.ApiResponse; diff --git a/src/main/java/com/fkzy/warn/controller/ReportController.java b/src/main/java/com/fkzy/warn/controller/ReportController.java index a3d098f..9b5c58a 100644 --- a/src/main/java/com/fkzy/warn/controller/ReportController.java +++ b/src/main/java/com/fkzy/warn/controller/ReportController.java @@ -1,6 +1,6 @@ package com.fkzy.warn.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.model.Report; import com.fkzy.warn.model.params.GenerateReportParams; import com.fkzy.warn.service.ReportService; diff --git a/src/main/java/com/fkzy/warn/controller/VersionManageController.java b/src/main/java/com/fkzy/warn/controller/VersionManageController.java index 22c4f31..1cb1e56 100644 --- a/src/main/java/com/fkzy/warn/controller/VersionManageController.java +++ b/src/main/java/com/fkzy/warn/controller/VersionManageController.java @@ -1,6 +1,6 @@ package com.fkzy.warn.controller; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.fkzy.warn.model.VersionManage; import com.fkzy.warn.service.VersionManageService; import com.fkzy.warn.common.constants.ResponseMsgConstants; diff --git a/src/main/java/com/fkzy/warn/mapper/DictItemMapper.java b/src/main/java/com/fkzy/warn/mapper/DictItemMapper.java index 9e8177c..930645b 100644 --- a/src/main/java/com/fkzy/warn/mapper/DictItemMapper.java +++ b/src/main/java/com/fkzy/warn/mapper/DictItemMapper.java @@ -1,6 +1,6 @@ package com.fkzy.warn.mapper; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; diff --git a/src/main/java/com/fkzy/warn/mapper/DictMapper.java b/src/main/java/com/fkzy/warn/mapper/DictMapper.java index cfd6385..35df0d2 100644 --- a/src/main/java/com/fkzy/warn/mapper/DictMapper.java +++ b/src/main/java/com/fkzy/warn/mapper/DictMapper.java @@ -1,6 +1,6 @@ package com.fkzy.warn.mapper; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fkzy.warn.model.Dict; diff --git a/src/main/java/com/fkzy/warn/model/AImessage.java b/src/main/java/com/fkzy/warn/model/AImessage.java new file mode 100644 index 0000000..3997063 --- /dev/null +++ b/src/main/java/com/fkzy/warn/model/AImessage.java @@ -0,0 +1,20 @@ +package com.fkzy.warn.model; + +import lombok.Data; + +/** + * @author zhangjing + * @date 2026/03/18 15:23 + * @description + */ +@Data +public class AImessage { + /** + * 会话角色(user代表用户,assistant代表系统) + */ + String role; + /** + * 会话内容 + */ + String content; +} diff --git a/src/main/java/com/fkzy/warn/model/AccessToken.java b/src/main/java/com/fkzy/warn/model/AccessToken.java new file mode 100644 index 0000000..8b71d37 --- /dev/null +++ b/src/main/java/com/fkzy/warn/model/AccessToken.java @@ -0,0 +1,20 @@ +package com.fkzy.warn.model; + +import lombok.Data; + +/** + * @author zhangjing + * @date 2026/03/17 17:20 + * @description + */ +@Data +public class AccessToken { + private String accessKey; + + private String dateTime; + + private Long expires; + + private String publicKey; + +} diff --git a/src/main/java/com/fkzy/warn/model/ApiResult.java b/src/main/java/com/fkzy/warn/model/ApiResult.java new file mode 100644 index 0000000..d989289 --- /dev/null +++ b/src/main/java/com/fkzy/warn/model/ApiResult.java @@ -0,0 +1,17 @@ +package com.fkzy.warn.model; + +import lombok.Data; + +/** + * @author zhangjing + * @date 2026/03/17 17:16 + * @description + */ +@Data +public class ApiResult { + private Integer code; + + private String msg; + + private T data; // 使用泛型 T +} diff --git a/src/main/java/com/fkzy/warn/model/ChapterNode.java b/src/main/java/com/fkzy/warn/model/ChapterNode.java new file mode 100644 index 0000000..f8006a0 --- /dev/null +++ b/src/main/java/com/fkzy/warn/model/ChapterNode.java @@ -0,0 +1,38 @@ +package com.fkzy.warn.model; + +import lombok.Data; + +import java.util.List; + +/** + * @author zhangjing + * @date 2026/03/18 16:43 + * @description + */ +@Data +public class ChapterNode { + /** + * 节点类型 (例如: chapter, article, clause) + */ + private String type; + + /** + * 名称 + */ + private String name; + + /** + * 内容 + */ + private String content; + + /** + * 编码/序号 (用于排序,例如 "1", "2", "A", "B") + */ + private String code; + + /** + * 子节点列表 (例如: 该章节下的条款、款、项等) + */ + private List children; +} diff --git a/src/main/java/com/fkzy/warn/model/LawGroup.java b/src/main/java/com/fkzy/warn/model/LawGroup.java new file mode 100644 index 0000000..e7d032c --- /dev/null +++ b/src/main/java/com/fkzy/warn/model/LawGroup.java @@ -0,0 +1,76 @@ +package com.fkzy.warn.model; + +import lombok.Data; + +import java.util.Date; +import java.util.List; + +/** + * @author zhangjing + * @date 2026/03/18 15:11 + * @description + */ +@Data +public class LawGroup { + private String title; + private String organ; + private String pubDate; + private String exprityDate; + private String timeliness; + private String id; + + // 数据库或系统相关字段 + private String createBy; + private Date createTime; + private String updateBy; + private Date updateTime; + private String remark; + private Integer pageNum; + private Integer pageSize; + + // 核心业务字段 + + private String lawId; + private String base; + + private String preface; + + private String source; + + // 文件路径相关字段 + private String minioPath; + private String pdfPathName; + private String isPdf; + private String syncFlag; + + // 查询辅助字段 + private String timelinessIn; + private String cnt; + private String name; + private String titleEq; + private String titleIn; + private String pubdate_range_start; + private String pubdate_range_end; + private String content; + + // 系统标识字段 + private String fyopentoken; + private String fyopensysid; + private String fyopensign; + private String fyopserviceid; + + // 列表查询字段 + private List sourceList; + private List timelinessList; + private List organList; + private List pubDateList; + private List exprityDateList; + + // 排序字段 + private String sortItem; + private String sortMethod; + + // 其他状态字段 + private String isValid; + private String lawType; +} diff --git a/src/main/java/com/fkzy/warn/model/LawGroupInfo.java b/src/main/java/com/fkzy/warn/model/LawGroupInfo.java new file mode 100644 index 0000000..79cec9e --- /dev/null +++ b/src/main/java/com/fkzy/warn/model/LawGroupInfo.java @@ -0,0 +1,45 @@ +package com.fkzy.warn.model; + +import java.util.List; + +/** + * @author zhangjing + * @date 2026/03/18 16:25 + * @description + */ +public class LawGroupInfo { + /** + * 时间 + */ + private String time; + + /** + * 标题 + */ + private String title; + + /** + * 发布机构 + */ + private String organ; + + /** + * 失效日期 + */ + private String exprityDate; + + /** + * 时效性 (例如: 现行有效, 已废止, 尚未生效) + */ + private String timeliness; + + /** + * 文号 + */ + private String doc_number; + + /** + * 子节点列表 (例如: 附件、子通知等) + */ + private List children; +} diff --git a/src/main/java/com/fkzy/warn/model/LawPageData.java b/src/main/java/com/fkzy/warn/model/LawPageData.java new file mode 100644 index 0000000..c759a57 --- /dev/null +++ b/src/main/java/com/fkzy/warn/model/LawPageData.java @@ -0,0 +1,17 @@ +package com.fkzy.warn.model; + +import lombok.Data; + +import java.util.List; + +/** + * @author zhangjing + * @date 2026/03/18 16:03 + * @description + */ +@Data +public class LawPageData { + Integer total; + + List result; +} diff --git a/src/main/java/com/fkzy/warn/model/params/AILawParams.java b/src/main/java/com/fkzy/warn/model/params/AILawParams.java new file mode 100644 index 0000000..830b4ab --- /dev/null +++ b/src/main/java/com/fkzy/warn/model/params/AILawParams.java @@ -0,0 +1,25 @@ +package com.fkzy.warn.model.params; + +import com.fkzy.warn.model.AImessage; +import lombok.Data; + +import java.util.List; + +/** + * @author zhangjing + * @date 2026/03/18 15:26 + * @description + */ +@Data +public class AILawParams { + /** + * 模型标识 中国法研LLM + */ + String model; + /** + * 流式开关(固定值true) + */ + Boolean stream; + + List messages; +} diff --git a/src/main/java/com/fkzy/warn/model/params/LawGroupParam.java b/src/main/java/com/fkzy/warn/model/params/LawGroupParam.java new file mode 100644 index 0000000..3b4e468 --- /dev/null +++ b/src/main/java/com/fkzy/warn/model/params/LawGroupParam.java @@ -0,0 +1,68 @@ +package com.fkzy.warn.model.params; + +import lombok.Data; + +import java.util.List; + +/** + * @author zhangjing + * @date 2026/03/17 16:20 + * @description + */ +@Data +public class LawGroupParam { + /** + * 每页条数 + */ + private Integer pageSize; + + /** + * 当前页码 + */ + private Integer pageNum; + + /** + * 法规名称(关键词) + */ + private String title; + + /** + * 发布部门 + */ + private String organ; + + /** + * 时效状态(如:现行有效) + */ + private String timeliness; + + /** + * 发布时间 + */ + private String pubDate; + + /** + * 发布部门列表(支持多选) + */ + private List organList; + + /** + * 时效状态列表(支持多选) + */ + private List timelinessList; + + /** + * 发布时间列表(支持多选) + */ + private List pubDateList; + + /** + * 效力级别列表(如:地方政府规章) + */ + private List sourceList; + + /** + * 实施日期列表(如:2015) + */ + private List exprityDateList; +} diff --git a/src/main/java/com/fkzy/warn/model/params/PageParam.java b/src/main/java/com/fkzy/warn/model/params/PageParam.java new file mode 100644 index 0000000..0b3a5c0 --- /dev/null +++ b/src/main/java/com/fkzy/warn/model/params/PageParam.java @@ -0,0 +1,25 @@ +package com.fkzy.warn.model.params; + +import lombok.Data; + +import java.util.List; + +/** + * @author zhangjing + * @date 2026/03/17 16:20 + * @description + */ +@Data +public class PageParam { + /** + * 每页条数 + */ + private Integer pageSize; + + /** + * 当前页码 + */ + private Integer pageNum; + + +} diff --git a/src/main/java/com/fkzy/warn/service/AuthorizationService.java b/src/main/java/com/fkzy/warn/service/AuthorizationService.java index c685e39..98ca9e9 100644 --- a/src/main/java/com/fkzy/warn/service/AuthorizationService.java +++ b/src/main/java/com/fkzy/warn/service/AuthorizationService.java @@ -1,6 +1,6 @@ package com.fkzy.warn.service; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.fkzy.warn.common.request.RequestParameter; diff --git a/src/main/java/com/fkzy/warn/service/EnterpriseInfoService.java b/src/main/java/com/fkzy/warn/service/EnterpriseInfoService.java index 7099a91..641317f 100644 --- a/src/main/java/com/fkzy/warn/service/EnterpriseInfoService.java +++ b/src/main/java/com/fkzy/warn/service/EnterpriseInfoService.java @@ -1,6 +1,6 @@ package com.fkzy.warn.service; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.extension.service.IService; import com.fkzy.warn.model.EnterpriseInfo; diff --git a/src/main/java/com/fkzy/warn/service/FyApiService.java b/src/main/java/com/fkzy/warn/service/FyApiService.java new file mode 100644 index 0000000..b66788a --- /dev/null +++ b/src/main/java/com/fkzy/warn/service/FyApiService.java @@ -0,0 +1,23 @@ +package com.fkzy.warn.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.fkzy.warn.model.LawCase; +import com.fkzy.warn.model.params.AILawParams; +import com.fkzy.warn.model.params.LawGroupParam; + +import java.util.List; + +/** + * @author zhangjing + * @date 2023/10/16 18:17 + * @description + */ +public interface FyApiService extends IService { + void getAccessToken(); + + void getLawGroup(LawGroupParam lawGroupParam); + + void getLawGroupInfo(String id); + + void sendAILaw(AILawParams aiLawParams); +} diff --git a/src/main/java/com/fkzy/warn/service/InvocationRecordService.java b/src/main/java/com/fkzy/warn/service/InvocationRecordService.java index 170c41a..ba1e275 100644 --- a/src/main/java/com/fkzy/warn/service/InvocationRecordService.java +++ b/src/main/java/com/fkzy/warn/service/InvocationRecordService.java @@ -1,6 +1,6 @@ package com.fkzy.warn.service; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.fkzy.warn.common.request.RequestParameter; diff --git a/src/main/java/com/fkzy/warn/service/LawCaseService.java b/src/main/java/com/fkzy/warn/service/LawCaseService.java index cab9757..cd22c31 100644 --- a/src/main/java/com/fkzy/warn/service/LawCaseService.java +++ b/src/main/java/com/fkzy/warn/service/LawCaseService.java @@ -1,6 +1,6 @@ package com.fkzy.warn.service; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.extension.service.IService; import com.fkzy.warn.model.LawCase; diff --git a/src/main/java/com/fkzy/warn/service/UserService.java b/src/main/java/com/fkzy/warn/service/UserService.java index dd8ba2c..2aa45ca 100644 --- a/src/main/java/com/fkzy/warn/service/UserService.java +++ b/src/main/java/com/fkzy/warn/service/UserService.java @@ -1,6 +1,7 @@ package com.fkzy.warn.service; -import com.alibaba.fastjson.JSONObject; + +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.fkzy.warn.common.request.RequestParameter; diff --git a/src/main/java/com/fkzy/warn/service/impl/AlarmCaseServiceImpl.java b/src/main/java/com/fkzy/warn/service/impl/AlarmCaseServiceImpl.java index 4dfe490..5c4e7e8 100644 --- a/src/main/java/com/fkzy/warn/service/impl/AlarmCaseServiceImpl.java +++ b/src/main/java/com/fkzy/warn/service/impl/AlarmCaseServiceImpl.java @@ -1,7 +1,7 @@ package com.fkzy.warn.service.impl; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; diff --git a/src/main/java/com/fkzy/warn/service/impl/AuthorizationServiceImpl.java b/src/main/java/com/fkzy/warn/service/impl/AuthorizationServiceImpl.java index 752b9ea..a3559cc 100644 --- a/src/main/java/com/fkzy/warn/service/impl/AuthorizationServiceImpl.java +++ b/src/main/java/com/fkzy/warn/service/impl/AuthorizationServiceImpl.java @@ -1,6 +1,6 @@ package com.fkzy.warn.service.impl; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fkzy.warn.mapper.AuthorizationMapper; diff --git a/src/main/java/com/fkzy/warn/service/impl/EnterpriseInfoServiceImpl.java b/src/main/java/com/fkzy/warn/service/impl/EnterpriseInfoServiceImpl.java index d5a453a..879cd71 100644 --- a/src/main/java/com/fkzy/warn/service/impl/EnterpriseInfoServiceImpl.java +++ b/src/main/java/com/fkzy/warn/service/impl/EnterpriseInfoServiceImpl.java @@ -1,8 +1,8 @@ package com.fkzy.warn.service.impl; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fkzy.warn.common.constants.EntityConstants; diff --git a/src/main/java/com/fkzy/warn/service/impl/FyApiServiceImpl.java b/src/main/java/com/fkzy/warn/service/impl/FyApiServiceImpl.java new file mode 100644 index 0000000..617d3cb --- /dev/null +++ b/src/main/java/com/fkzy/warn/service/impl/FyApiServiceImpl.java @@ -0,0 +1,373 @@ +package com.fkzy.warn.service.impl; + + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson2.TypeReference; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.fkzy.warn.common.constants.LawResearchUrlConstants; +import com.fkzy.warn.common.util.MD5Util; +import com.fkzy.warn.common.util.RedisUtil; +import com.fkzy.warn.mapper.LawCaseMapper; +import com.fkzy.warn.model.*; +import com.fkzy.warn.model.params.AILawParams; +import com.fkzy.warn.model.params.LawGroupParam; +import com.fkzy.warn.model.params.PageParam; +import com.fkzy.warn.service.FyApiService; +import com.fkzy.warn.service.InvocationRecordService; +import lombok.extern.slf4j.Slf4j; +import okhttp3.*; +import okio.BufferedSource; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.*; +import org.springframework.http.MediaType; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import javax.annotation.Resource; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +/** + * @author zhangjing + * @date 2023/10/16 18:17 + * @description + */ +@Slf4j +@Service +public class FyApiServiceImpl extends ServiceImpl implements FyApiService { + + @Value(value = "${api.accessTokenUrl}") + private String accessTokenUrl; + + @Value(value = "${api.appKey}") + private String appKey; + @Value(value = "${api.appSecret}") + private String appSecret; + + @Value(value = "${api.lawGroupUrl}") + private String lawGroupUrl; + + @Value(value = "${api.lawGroupInfoUrl}") + private String lawGroupInfoUrl; + + @Value(value = "${api.aiLawUrl}") + private String aiLawUrl; + + @Value(value = "${api.apiId}") + private String apiId; + @Resource + RedisUtil redisUtil; + @Resource + InvocationRecordService invocationRecordService; + + + @Override + public void getAccessToken() { + try { + String result = postAccessToken(accessTokenUrl, appKey, appSecret); + ApiResult apiResult = JSON.parseObject( + result, + new TypeReference>() { + } + ); + if (apiResult != null && apiResult.getCode().equals(1000)) { + String accessKey = apiResult.getData().getAccessKey(); + redisUtil.del("accessKey"); + redisUtil.set("accessKey", accessKey, 60 * 48); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void getLawGroup(LawGroupParam lawGroupParam) { +// getAccessToken(); +// if (true){ +// return; +// } + + PageParam pageParam = new PageParam(); + pageParam.setPageNum(1); + pageParam.setPageSize(20); + String json = JSON.toJSONString(lawGroupParam); + HttpHeaders headers = getRequestHeader(json); + String result = postAip(lawGroupUrl, headers, json, "法研平台-法律法规分组列表"); + ApiResult> resultData = JSON.parseObject( + result, + new TypeReference>>() { + } + ); + } + + @Override + public void getLawGroupInfo(String id) { + JSONObject object = new JSONObject(); + object.put("id", id); + String json = object.toJSONString(); + HttpHeaders headers = getRequestHeader(json); + String result = postAip(lawGroupInfoUrl, headers, json, "法研平台-法律法规详情"); + ApiResult resultData = JSON.parseObject( + result, + new TypeReference>() { + } + ); + } + + @Override + public void sendAILaw(AILawParams aiLawParams) { +// getAccessToken(); +// if (true) { +// return; +// } + String jsonParams = JSON.toJSONString(aiLawParams); + HttpHeaders headers = getRequestHeader(jsonParams); + postStream(aiLawUrl, headers, jsonParams, "法研平台-AI检索法规"); + } + /** + * 发送流式请求到指定URL,并处理SSE响应 + * + * @param url 请求的完整URL + * @param headers 已经构建好的请求头,应包含认证等信息 + * @param jsonParams JSON格式的请求体 + * @param logDesc 用于日志描述的标识 + */ + public void postStream(String url, HttpHeaders headers, String jsonParams, String logDesc) { + + + // 1. 创建 OkHttpClient 实例 + OkHttpClient client = new OkHttpClient.Builder() + .connectTimeout(30, TimeUnit.SECONDS) + // SSE是长连接,设置较长的读取超时 + .readTimeout(5, TimeUnit.MINUTES) + .build(); + + // 2. 构建 Request + okhttp3.MediaType JSON_TYPE = okhttp3.MediaType.parse("application/json; charset=utf-8"); + RequestBody body = RequestBody.create(JSON_TYPE, jsonParams); + + Request.Builder requestBuilder = new Request.Builder() + .url(url) + .post(body); + + // 将 Spring 的 HttpHeaders 复制到 OkHttp 的 Request.Builder 中 + for (String headerName : headers.keySet()) { + String headerValue = headers.getFirst(headerName); + if (headerValue != null) { + requestBuilder.addHeader(headerName, headerValue); + } + } + + Request request = requestBuilder.build(); + + // 3. 发起异步请求 + Call call = client.newCall(request); + call.enqueue(new Callback() { + @Override + public void onFailure(Call call, IOException e) { + System.err.println(logDesc + " - 请求失败: " + e.getMessage()); + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + try { + if (!response.isSuccessful()) { + System.err.println(logDesc + " - 请求失败,状态码: " + response.code()); + System.err.println(logDesc + " - 错误响应体: " + response.body().string()); + return; + } + + // 检查 Content-Type + String contentType = response.header("Content-Type"); + if (contentType != null && contentType.toLowerCase().contains("text/event-stream")) { + System.out.println(logDesc + " - 检测到 content-type: " + contentType); + } else { + System.err.println(logDesc + " - 警告: 响应的 content-type 不是 'text/event-stream': " + contentType); + } + + // 获取响应体源 + ResponseBody responseBody = response.body(); + if (responseBody == null) { + System.err.println(logDesc + " - 响应体为空"); + return; + } + + BufferedSource source = responseBody.source(); + + System.out.println(logDesc + " - 请求成功,开始处理流式响应..."); + + // 4. 逐行读取并处理流 + while (!source.exhausted()) { + String line = source.readUtf8LineStrict(); + + + if (line.startsWith("data:")) { + // 提取 data 字段后的 JSON 内容 + String jsonData = line.substring(5).trim(); // 去掉 "data:" 前缀和空格 + try { + // 假设服务器返回的 data 是 JSON,可以使用 Fastjson2 解析 + Object parsedData = JSON.parse(jsonData); + System.out.println(logDesc + " - 收到数据: " + parsedData); + // 在这里,你可以将 parsedData 转换为你需要的对象类型, + // 并进行后续的业务处理 + } catch (Exception e) { + // 如果 data 不是 JSON,直接打印 + System.out.println(logDesc + " - 收到非JSON数据: " + jsonData); + } + } else if (line.startsWith("event:") || line.startsWith("id:") || line.startsWith("retry:")) { + // 处理其他 SSE 事件字段 (如果需要) + System.out.println(logDesc + " - SSE Event Line: " + line); + } else if (line.isEmpty()) { + // SSE 规范中,空行表示一个事件的结束 + // System.out.println(logDesc + " - Event End (empty line)"); + } else { + // 有些服务器可能直接发送数据而不带 "data:" 前缀 + System.out.println(logDesc + " - Received raw line: " + line); + } + } + System.out.println(logDesc + " - 流式响应处理完毕。"); + + } finally { + response.close(); // 确保资源被释放 + } + } + }); + + System.out.println(logDesc + " - 异步请求已发送,正在监听流式响应..."); + } + private String postAip(String lawGroupUrl, HttpHeaders headers + , String request, String apiName) { + //接口调用日志 + InvocationRecord invocationRecord = new InvocationRecord(); + + RestTemplate restTemplate = new RestTemplate(); + HttpComponentsClientHttpRequestFactory requestFactory + = new HttpComponentsClientHttpRequestFactory(); + requestFactory.setConnectionRequestTimeout(60000); + requestFactory.setConnectTimeout(60000); + requestFactory.setReadTimeout(60000); + restTemplate.setRequestFactory(requestFactory); + try { + HttpEntity entity = new HttpEntity<>(request, headers); + ResponseEntity response = restTemplate.exchange( + lawGroupUrl, + HttpMethod.POST, + entity, + String.class + ); + + String rawResponseBody = response.getBody(); + String resultData; + + // 获取响应头中的 Content-Type + String contentType = response.getHeaders().getContentType().toString(); + if (contentType != null && contentType.toLowerCase().contains("charset=utf-8")) { + // 指定了UTF-8,则使用UTF-8解码 + resultData = new String(rawResponseBody.getBytes("ISO-8859-1"), "UTF-8"); + } else { + // 兜底 + resultData = new String(rawResponseBody.getBytes("ISO-8859-1"), "UTF-8"); + } + + //日志 + invocationRecord.setApiUrl(lawGroupUrl); + if (request != null) { + invocationRecord.setInputObj(request); + } + invocationRecord.setApiName(apiName); + invocationRecord.setIsSuccess(0); + invocationRecord.setApiResult(resultData); + JSONObject jsonObject = JSONObject.parseObject(resultData); + if (jsonObject != null && jsonObject.getString("code").equals("1000")) { + invocationRecord.setIsSuccess(1); + return resultData; + } + + } catch (Exception e) { + // 记录失败情况 + invocationRecord.setIsSuccess(0); + invocationRecord.setApiResult("Error: " + e.getMessage()); + e.printStackTrace(); // 或者使用更合适的日志框架 + } finally { + // 无论成功还是失败,都确保记录被保存 + invocationRecordService.save(invocationRecord); + } + return null; + } + + private HttpHeaders getRequestHeader(String params) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("FYDN-OP-RequestId", UUID.randomUUID().toString().replaceAll("-", "")); + // 签名串,使用在线文档中的MD5Util示例加密生成 + String sortString = MD5Util.sortJsonToStr(params); + String sign = MD5Util.md5Sign(sortString, appKey); + headers.set("FYDN-OP-Sign", sign); + // 需要从getAccessToken返回结果中解析出accessKey,返回结构样例参考在线文档 + String accessToken = getRedisAccessToken(); + headers.set("FYDN-OP-AccessToken", accessToken); + headers.set("FYDN-OP-AppID", apiId); + // 调用的环境(prod:线上环境,默认;test:测试环境) + headers.set("FYDN-OP-Env", "prod"); + // 用户所在系统的唯一标识 + headers.set("FYDN-OP-UserId", ""); + return headers; + } + + private String getRedisAccessToken() { + String accessToken = redisUtil.getString("accessKey"); + if (accessToken == null) { + getAccessToken(); + accessToken = redisUtil.getString("accessKey"); + } + if (accessToken != null && accessToken.startsWith("\"") && accessToken.endsWith("\"")) { + // 使用 substring 去掉第一个和最后一个字符 + return accessToken.substring(1, accessToken.length() - 1); + } + return accessToken; + } + + public String postAccessToken(String apiUrl, String appKey, String appSecret) throws Exception { + // 将 paramMap 转为 JSON 字符串 + + try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + HttpPost httpPost = new HttpPost(apiUrl); + + RequestConfig config = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(10000).setConnectionRequestTimeout(10000).build(); + httpPost.setConfig(config); + + // 构造 x-www-form-urlencoded 参数 + String params = "appKey=" + URLEncoder.encode(appKey, StandardCharsets.UTF_8.toString()) + "&appSecret=" + URLEncoder.encode(appSecret, StandardCharsets.UTF_8.toString()); + + StringEntity entity = new StringEntity(params, StandardCharsets.UTF_8); + httpPost.setEntity(entity); + httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); + + try (CloseableHttpResponse response = httpclient.execute(httpPost)) { + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode == 200) { + org.apache.http.HttpEntity resEntity = response.getEntity(); + return EntityUtils.toString(resEntity, StandardCharsets.UTF_8); + } else { + System.err.println("HTTP Error: " + statusCode); + return null; + } + } + } + } + + +} diff --git a/src/main/java/com/fkzy/warn/service/impl/LawCaseServiceImpl.java b/src/main/java/com/fkzy/warn/service/impl/LawCaseServiceImpl.java index 2f01540..f579fde 100644 --- a/src/main/java/com/fkzy/warn/service/impl/LawCaseServiceImpl.java +++ b/src/main/java/com/fkzy/warn/service/impl/LawCaseServiceImpl.java @@ -1,8 +1,8 @@ package com.fkzy.warn.service.impl; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fkzy.warn.common.constants.EntityConstants; @@ -204,14 +204,14 @@ public class LawCaseServiceImpl extends ServiceImpl impl // ReportModel reportModel = createReportData(); // ReportUtil.createReport(reportModel); - String filePath = "丰县城市建设投资集团有限公司-司法.txt"; -// String filePath = "工商.txt"; - String jsonOutput = convertTextToJson(filePath); - if (jsonOutput == null) { - logger.error("转换失败,JSON 字符串为空"); - return; - } - jsonObject = new JSONObject().parseObject(jsonOutput); +// String filePath = "丰县城市建设投资集团有限公司-司法.txt"; +//// String filePath = "工商.txt"; +// String jsonOutput = convertTextToJson(filePath); +// if (jsonOutput == null) { +// logger.error("转换失败,JSON 字符串为空"); +// return; +// } +// jsonObject = new JSONObject().parseObject(jsonOutput); // enterpriseInfoService.industryModelSave(jsonObject); JSONArray arr = jsonObject.getJSONArray("data"); if (arr == null || arr.isEmpty()) { @@ -247,7 +247,7 @@ public class LawCaseServiceImpl extends ServiceImpl impl // 八类案件 JSONObject detail = data.getJSONObject("detail"); -// setCases(detail, companyName, creditCode); + setCases(detail, companyName, creditCode); //案件树 JSONObject tree = detail.getJSONObject("cases_tree"); JSONArray civil = tree.getJSONArray("civil"); diff --git a/src/main/java/com/fkzy/warn/service/impl/MonitorUsersServiceImpl.java b/src/main/java/com/fkzy/warn/service/impl/MonitorUsersServiceImpl.java index 3874a7e..fa78014 100644 --- a/src/main/java/com/fkzy/warn/service/impl/MonitorUsersServiceImpl.java +++ b/src/main/java/com/fkzy/warn/service/impl/MonitorUsersServiceImpl.java @@ -1,6 +1,6 @@ package com.fkzy.warn.service.impl; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -112,6 +112,8 @@ public class MonitorUsersServiceImpl extends ServiceImpl