Sfoglia il codice sorgente

feat:增加获取党建系统政治面貌数据

huangliwei 1 giorno fa
parent
commit
b6a4180f1a

+ 95 - 0
code/hr/nckd-jxccl-hr/src/main/java/nckd/jxccl/hr/ApiClient.java

@@ -0,0 +1,95 @@
+package nckd.jxccl.hr;
+
+import com.alibaba.fastjson.JSONObject;
+import com.google.logging.type.HttpRequest;
+import kd.bos.flydb.jdbc.client.impl.HttpClient;
+import kd.bos.krpc.common.URL;
+import kd.bos.util.HttpClientUtils;
+import kd.bos.util.StringUtils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Author: HLW
+ * @Description:
+ * @Date: 4/11/2025 下午 4:52
+ * @Version: 1.0
+ **/
+
+public class ApiClient {
+    public static String getToken(String allUri)
+    {
+        String accessToken = null;
+
+        if(allUri != null) {
+            // 请求头
+            Map<String, String> header = new HashMap<>();
+            header.put("Content-Type", "application/json");
+            // 如果需要其他头信息,可以继续添加
+            // header.put("Accept", "application/json");
+
+            try {
+                // 使用GET方法调用接口,params传null或空字符串
+                String json = HttpClientUtils.get(allUri, header, null, 1000000, 1000000);
+
+                if(StringUtils.isNotEmpty(json)) {
+                    JSONObject jsonObject = JSONObject.parseObject(json);
+                    // 根据实际返回的JSON字段获取token
+                    // 如果返回字段是"access_token"
+                    accessToken = String.valueOf(jsonObject.get("result"));
+                    // 或者如果是其他字段名,比如"token"
+                    // accessToken = String.valueOf(jsonObject.get("token"));
+                }
+
+            } catch (Exception e) {
+                e.printStackTrace(); // 建议添加日志以便调试
+                return accessToken;
+            }
+        }
+        return accessToken;
+    }
+
+    public static String getPoliticalPartyData(String uri, String sysCode, String accessToken, String code, String jsonDataStr){
+        String result = null;
+
+        if(uri != null  && StringUtils.isNotEmpty(sysCode) && StringUtils.isNotEmpty(accessToken)) {
+            // 请求头
+            Map<String, String> header = new HashMap<>();
+            header.put("Content-Type", "application/json");
+            header.put("sysCode", sysCode);
+            header.put("accessToken", accessToken);
+            // 如果需要其他头信息,可以继续添加
+            // header.put("Accept", "application/json");
+
+            // 构造Body参数
+            JSONObject bodyParams = new JSONObject();
+            bodyParams.put("code", code);
+            JSONObject jsonData = JSONObject.parseObject(jsonDataStr);
+            bodyParams.put("jsonData", jsonData);
+            String params = bodyParams.toJSONString();
+
+            try {
+                /// 调用POST接口
+                String json = HttpClientUtils.postjson(uri, header, params, 1000000, 1000000);
+
+                if(StringUtils.isNotEmpty(json)) {
+                    // 如果需要解析特定字段,可以这样:
+                     JSONObject jsonObject = JSONObject.parseObject(json);
+                     result = String.valueOf(jsonObject.get("result"));
+                }
+
+            } catch (Exception e) {
+                e.printStackTrace(); // 建议添加日志以便调试
+                return result;
+            }
+        }
+        return result;
+    }
+}