From 8009db163dda5fe1e3f772e1e1bb808b5db8132a Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@tuqin.cn>
Date: 星期四, 22 十月 2026 22:29:48 +0800
Subject: [PATCH] fix(浪潮SSO): 单点登录增加容错与日志(同步自 dev_tide_wrzs)

---
 src/main/java/com/ruoyi/tide/utils/TideUtils.java |   51 ++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/ruoyi/tide/utils/TideUtils.java b/src/main/java/com/ruoyi/tide/utils/TideUtils.java
index 3fec16d..dff51f8 100644
--- a/src/main/java/com/ruoyi/tide/utils/TideUtils.java
+++ b/src/main/java/com/ruoyi/tide/utils/TideUtils.java
@@ -9,6 +9,7 @@
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
@@ -21,9 +22,26 @@
 @Component
 @Slf4j
 public class TideUtils {
-    private final static String appId = "1151162645026439168";
 
-    private final static String appSecret = "t1BsMDgwODIwMjUxMTUwMjc3NzMdNi";
+    public static String APP_ID;
+    public static String APP_SECRET;
+
+
+    @Value("${inspur.appId}")
+    private String appId;
+
+    @Value("${inspur.appSecret}")
+    private String appSecret;
+
+    @Value("${inspur.appId}")
+    public void setAppId(String appId) {
+        TideUtils.APP_ID = appId;
+    }
+
+    @Value("${inspur.appSecret}")
+    public void setAppSecret(String appSecret) {
+        TideUtils.APP_SECRET = appSecret;
+    }
 
     // 鍐呯綉鍦板潃
     private final static String ip = "http://10.136.0.8:8083";
@@ -62,14 +80,14 @@
             xSignSplicingTogether = "x-random=" + xRandom + "&x-time=" + xTime;
         }
         // 閰嶇疆鍔犲瘑鏂瑰紡涓庡瘑閽�
-        HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, appSecret.getBytes());
+        HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, APP_SECRET.getBytes());
         // 寰楀嚭x-sign
         String xSign = hMac.digestHex(xSignSplicingTogether);
         HashMap<String, String> result = new HashMap<>();
         result.put("x-time", xTime);
         result.put("x-random", xRandom);
         result.put("x-sign", xSign);
-        result.put("appKey", appId);
+        result.put("appKey", APP_ID);
         return result;
     }
 
@@ -91,13 +109,13 @@
             xSignSplicingTogether = "x-random=" + xRandom + "&x-time=" + xTime;
         }
         // x-sign 鍔犲瘑
-        HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, appSecret.getBytes());
+        HMac hMac = new HMac(HmacAlgorithm.HmacSHA256, APP_SECRET.getBytes());
         String xSign = hMac.digestHex(xSignSplicingTogether);
         HashMap<String, String> result = new HashMap<>();
         result.put("x-time", xTime);
         result.put("x-random", xRandom);
         result.put("x-sign", xSign);
-        result.put("appKey", appId);
+        result.put("appKey", APP_ID);
         return result;
     }
 
@@ -117,30 +135,41 @@
         String url = ip + "/cpn/extral/applicationCode/appAuthCheck";
         JSONObject json = new JSONObject();
         json.put("code", code);
-        json.put("appID", appId);
-        json.put("appSecret", appSecret);
+        json.put("appID", APP_ID);
+        json.put("appSecret", APP_SECRET);
         HashMap<String, String> header = getPostHeader(json.toString());
         String body = HttpRequest.post(url)
                 .headerMap(header, false)
                 .body(json.toString())
                 .execute().body();
+        log.info("[娴疆SSO] appAuthCheck 杩斿洖: {}", body);
         JSONObject jsonObject = JSONObject.parseObject(body);
-        return jsonObject.get("data").toString();
+        Object data = jsonObject == null ? null : jsonObject.get("data");
+        return data == null ? null : data.toString();
     }
 
     // 鑾峰彇鐢ㄦ埛淇℃伅
     public static JSONObject getUserInfo(String token) {
         String url = ip + "/cpn/api/extral/applicationCode/getUserInfoByToken";
         JSONObject json = new JSONObject();
-        json.put("appID", appId);
+        json.put("appID", APP_ID);
         HashMap<String, String> header = getPostHeader(json.toString());
         header.put("Authorization", token);
         String body = HttpRequest.post(url)
                 .headerMap(header, false)
                 .body(json.toString())
                 .execute().body();
+        log.info("[娴疆SSO] getUserInfoByToken 杩斿洖: {}", body);
         JSONObject jsonObject = JSONObject.parseObject(body);
-        return JSONObject.parseObject(jsonObject.get("data").toString());
+        Object data = jsonObject == null ? null : jsonObject.get("data");
+        if (data == null) {
+            return null;
+        }
+        String dataStr = data.toString();
+        if (dataStr.isEmpty() || "null".equalsIgnoreCase(dataStr)) {
+            return null;
+        }
+        return JSONObject.parseObject(dataStr);
     }
 
     public static JSONObject getResult(Integer code, String msg, Object data) {

--
Gitblit v1.9.3