1037015548@qq.com 2 سال پیش
والد
کامیت
523198ff03

+ 27 - 25
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/ActionApi.java

@@ -33,7 +33,7 @@ public class ActionApi {
 
     @Autowired
     private IDanganService danganService;
-    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
+    private static final Logger logger = LoggerFactory.getLogger("sys-user");
 
     /**
      * JSESSIONID=abbf57c4-eb7e-4ce8-9556-061a1cb9c016
@@ -43,10 +43,10 @@ public class ActionApi {
      */
     @ApiOperation("子系统调AD")
     @PostMapping()
-    public AjaxResult userList(@RequestBody ValidateMessage validateMessage)throws Exception
+    public AjaxResult userList(@RequestBody ValidateMessage validateMessage)
     {
 
-
+    try {
         if (!StringUtils.isNotEmpty(validateMessage.getClientKey())) {
             return AjaxResult.error("请求失败!");
 
@@ -67,11 +67,12 @@ public class ActionApi {
 
         //TODO 新逻辑 传递的reqid加上了自定义的字符串newReqid+时间,
         //TODO 所以要取掉该字符串以便保证原逻辑不变的情况下设定每分钟更新新的reqid的进行验证,即当前系统会话内每一分钟传递新的reqid
-        if(!StringUtils.isEmpty(validateMessage.getReqid())){
+        logger.info("reqid=" + validateMessage.getReqid());
+        if (!StringUtils.isEmpty(validateMessage.getReqid())) {
             String reqid = validateMessage.getReqid();
-            if(reqid.indexOf("newReqid")>0){
+            if (reqid.indexOf("newReqid") > 0) {
                 String[] reqidlist = reqid.split("newReqid");
-                if(reqidlist.length>1){
+                if (reqidlist.length > 1) {
                     //TODO 说明有newReqid
                     long nd = 1000 * 24 * 60 * 60;
                     long nh = 1000 * 60 * 60;
@@ -81,42 +82,38 @@ public class ActionApi {
                     // 获得两个时间的毫秒时间差异
                     long diff = new Date().getTime() - date.getTime();
                     long min = diff % nd % nh / nm;
-                    if(min>1){
+                    if (min > 1) {
                         logger.error("reqid已过期");
                         return AjaxResult.error("授权已过期!");
                     }
                 }
-                StringBuilder stringBuilder = new StringBuilder(reqid);
-                stringBuilder.replace(reqid.indexOf("newReqid"),reqid.length(),"");
-                validateMessage.setReqid(stringBuilder.toString());
+                validateMessage.setReqid(reqidlist[0]);
             }
-        }else{
+        } else {
             logger.error("子系统未传递reqid");
         }
-        SysUserOnline sysUserOnline = onlineService.selectOnlineById( validateMessage.getReqid());
+        logger.info("reqidOut=" + validateMessage.getReqid());
+        SysUserOnline sysUserOnline = onlineService.selectOnlineById(validateMessage.getReqid());
 
         if (StringUtils.isNull(sysUserOnline)) {
-
+            logger.error("授权已过期!");
             return AjaxResult.error("授权已过期!");
         }
         String authCode = validateMessage.getAuthCode();
         Dangan dangan = danganService.selectDanganByDanganName(validateMessage.getCid());
         String keyId = dangan.getKeyId();
-        String auth= keyId+validateMessage.getReqid();
+        String auth = keyId + validateMessage.getReqid();
 
-        auth=new Md5Hash(auth).toHex();
+        auth = new Md5Hash(auth).toHex();
         if (!auth.equals(authCode)) {
+            logger.error("授权码错误!");
             return AjaxResult.error("授权码错误!");
         }
 
 
-
         // bbccji7920f9df-baa7-4e9c-9e68-72c79454589a
 
 
-
-
-
         String loginName = sysUserOnline.getLoginName();
         UserRelate userRelate = new UserRelate();
         userRelate.setLoginName(loginName);
@@ -125,6 +122,7 @@ public class ActionApi {
         List<UserRelate> userRelates = userRelateService.selectUserRelateList(userRelate);
 
         if (!StringUtils.isNotEmpty(userRelates)) {
+            logger.error("授权已过期!");
             return AjaxResult.error("授权已过期!");
         }
 
@@ -132,14 +130,18 @@ public class ActionApi {
         //把用户名返回去
 
         //生成校验码
-        String str= keyId+validateMessage.getClientKey();
-        str=new Md5Hash(str).toHex();
-
-        AjaxResult ajaxResult=AjaxResult.success();
-        ajaxResult.put("loginName",userRelate1.getDanganLoginName());
-        ajaxResult.put("rspid",str);
+        String str = keyId + validateMessage.getClientKey();
+        str = new Md5Hash(str).toHex();
 
+        AjaxResult ajaxResult = AjaxResult.success();
+        ajaxResult.put("loginName", userRelate1.getDanganLoginName());
+        ajaxResult.put("rspid", str);
+        logger.error("授权成功!",ajaxResult.toString());
         return ajaxResult;
+        }catch(Exception ex){
+            logger.error("异常:"+ex.getLocalizedMessage());
+            return AjaxResult.error("异常");
+        }
     }
 
 

+ 2 - 1
ruoyi-admin/src/main/resources/templates/view.html

@@ -190,7 +190,8 @@
     function opennewpage(url,danganLoginName) {
         // window.location.href=url;
         let newReqid = "newReqid"+new Date().getTime();
-        url = url+"?"+"reqid="+sessionId+newReqid;
+        url = url+"?"+"reqid="+sessionId+newReqid.trim();
+        // url = url+"?"+"reqid="+sessionId;
         console.log(url)
 
         //TODO 先跑一个接口进行会话验证,判断当前登录是否过期在进行跳转

+ 27 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/html/EscapeUtil.java

@@ -1,6 +1,11 @@
 package com.ruoyi.common.utils.html;
 
+import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
+import org.apache.poi.ss.usermodel.DateUtil;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 /**
  * 转义和反转义工具类
@@ -163,5 +168,27 @@ public class EscapeUtil
         System.out.println("clean: " + EscapeUtil.clean(html));
         System.out.println("escape: " + escape);
         System.out.println("unescape: " + EscapeUtil.unescape(escape));
+
+        String reqid = "81b2c95d-2126-4326-bd2e-4936916863c6newReqid1683799523958";
+            if(reqid.indexOf("newReqid")>0){
+                String[] reqidlist = reqid.split("newReqid");
+                if(reqidlist.length>1){
+                    //TODO 说明有newReqid
+                    long nd = 1000 * 24 * 60 * 60;
+                    long nh = 1000 * 60 * 60;
+                    long nm = 1000 * 60;
+                    String time = reqidlist[1];
+                    Date date = new Date(Long.valueOf(time));
+                    // 获得两个时间的毫秒时间差异
+                    long diff = new Date().getTime() - date.getTime();
+                    long min = diff % nd % nh / nm;
+                    if(min>1){
+
+                    }
+                }
+                StringBuilder stringBuilder = new StringBuilder(reqid);
+                stringBuilder.replace(reqid.indexOf("newReqid"),reqid.length(),"");
+                System.out.println(stringBuilder.toString());
+            }
     }
 }