From c161e54886d869964b74959f1ad228d24d360849 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期五, 16 一月 2026 10:29:37 +0800
Subject: [PATCH] 【景宁】SSO单点登录接口

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/sso/SSOController.java |   42 +++++++++++++++++++-----------------------
 1 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/sso/SSOController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/sso/SSOController.java
index 5955095..0a429a9 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/sso/SSOController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/sso/SSOController.java
@@ -129,32 +129,35 @@
     @GetMapping("ssoLoginLyra")
     public RedirectView ssoLoginLyra() {
         log.info("鏀跺埌SSO鐧诲綍璇锋眰锛屽紑濮嬮噸瀹氬悜鍒版巿鏉冩湇鍔″櫒");
-        String id = clientId;
         String redirectUri = internalRedirectUri;
+        String path = sysConfigService.selectConfigByKey("sys.qddz");
+        String lyraPath = "https://9.208.39.29:13021";
+        String clientId = "1553548571532333056";
+        String clientSecret = "suifangxt";
         String scope = "openid";
-        id = "1553548571532333056";
         redirectUri = URLEncoder.encode(internalRedirectUri);
+
+        String authorizeUrl = lyraPath + "/mediinfo-lyra-authserver/connect/authorize";
+        String accessTokenUrl = lyraPath + "/mediinfo-lyra-authserver/connect/token";
+        String userInfoUrl =  lyraPath + "/mediinfo-lyra-authserver/connect/userinfo";
         // 閲嶅畾鍚戝湴鍧�瀵硅薄(閲嶅畾鍚戝湴鍧�
         RedirectView redirectView = new RedirectView();
 
         // Authorize閴存潈鎺ュ彛
-        String param = "client_id=" + id + "&redirect_uri=" + redirectUri + "&response_type=code" +
+        String param = "client_id=" + clientId + "&redirect_uri=" + redirectUri + "&response_type=code" +
                 "&state=" + state + "&scope=" + scope;
         log.info("銆怉uthorize閴存潈鎺ュ彛銆戝叆鍙備负锛歿}", param);
-        String url = "https://9.208.39.29:13021" + "/mediinfo-lyra-authserver/connect/authorize";
 //        String url = internalAuthorizeUrl;
-        String s = HttpUtils.sendGet(url, param);
+        String s = HttpUtils.sendGet(authorizeUrl, param);
         Map<String, String> result = getResult(s);
         String code = result.get("code");
         if (StringUtils.isEmpty(code)) {
             log.error("鏈幏鍙栧埌鎺堟潈鐮�");
             throw new BaseException("SSO鎺堟潈澶辫触");
         }
-
-        String path = sysConfigService.selectConfigByKey("sys.qddz");
         try {
-            SSOTokenResponse accessToken = getAccessTokenLyra(code, true);
-            SSOUserInfo userInfo = getUserInfoLyra(accessToken.getAccess_token(), true);
+            SSOTokenResponse accessToken = getAccessTokenLyra(code, accessTokenUrl, clientId, clientSecret,true);
+            SSOUserInfo userInfo = getUserInfoLyra(accessToken.getAccess_token(), userInfoUrl,true);
 
             createLocalSession(userInfo);
             if (StringUtils.isEmpty(path)) {
@@ -269,27 +272,21 @@
     /**
      * 鑾峰彇璁块棶浠ょ墝
      */
-    private SSOTokenResponse getAccessTokenLyra(String code, boolean isInternal) throws Exception {
+    private SSOTokenResponse getAccessTokenLyra(String code, String accessTokenUrl, String clientId, String clientSecret, boolean isInternal) throws Exception {
         HttpHeaders headers = new HttpHeaders();
         headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
 
         MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
-        String id = clientId;
-        String secret = clientSecret;
-        String url = getTokenUrl(isInternal);
         String redirectUri = getRedirectUri(isInternal);
-        id = "1553548571532333056";
-        secret = "suifangxt";
-        url = "https://9.208.39.29:13021" + "/mediinfo-lyra-authserver/connect/token";
-        params.add("client_id", id);
-        params.add("client_secret", secret);
+        params.add("client_id", clientId);
+        params.add("client_secret", clientSecret);
         params.add("code", code);
         params.add("grant_type", "authorization_code");
         params.add("redirect_uri", redirectUri);
 
         HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);
 
-        ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
+        ResponseEntity<String> response = restTemplate.exchange(accessTokenUrl, HttpMethod.POST, request, String.class);
 
         log.info("Token鍝嶅簲: {}", response.getBody());
 
@@ -309,14 +306,13 @@
     /**
      * 鑾峰彇鐢ㄦ埛淇℃伅
      */
-    private SSOUserInfo getUserInfoLyra(String accessToken, boolean isInternal) throws Exception {
+    private SSOUserInfo getUserInfoLyra(String accessToken, String userInfoUrl, boolean isInternal) throws Exception {
         HttpHeaders headers = new HttpHeaders();
         headers.set("Authorization", "Bearer " + accessToken);
 
         HttpEntity<String> entity = new HttpEntity<>(headers);
-        String url = getUserinfoUrl(isInternal);
-        url = "https://9.208.39.29:13021" + "/mediinfo-lyra-authserver/connect/userinfo";
-        ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
+
+        ResponseEntity<String> response = restTemplate.exchange(userInfoUrl, HttpMethod.GET, entity, String.class);
 
         log.info("鐢ㄦ埛淇℃伅鍝嶅簲: {}", response.getBody());
 

--
Gitblit v1.9.3