LAPTOP-FO2T5SIU\35838 5 月之前
父節點
當前提交
4773221cd2
共有 1 個文件被更改,包括 78 次插入0 次删除
  1. 78 0
      pro-wx/src/main/java/com/idea/pro/wx/web/WxPubController.java

+ 78 - 0
pro-wx/src/main/java/com/idea/pro/wx/web/WxPubController.java

@@ -0,0 +1,78 @@
+package com.idea.pro.wx.web;
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.util.CharsetUtil;
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.crypto.symmetric.AES;
+import com.google.code.kaptcha.Constants;
+import com.rockstar.common.log.Log;
+import com.rockstar.frame.controller.HomeController;
+import com.rockstar.shiro.authc.EasyTypeToken;
+import com.rockstar.util.Constant;
+import com.rockstar.util.StringUtils;
+import io.swagger.annotations.Api;
+import org.apache.shiro.SecurityUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Created by pengyq on 2020.
+ */
+@Controller
+@RequestMapping(value = "/wx/pub")
+@Api(value="公共控制类")
+public class WxPubController extends HomeController {
+
+    @Value("${ssoKey}")
+    private String ssoKey;
+
+    @Log(title = "免密登录")
+    @PostMapping("/loginSecret")
+    @ResponseBody
+    public Map<String, Object> loginByKey(String username, HttpServletRequest request) {
+
+        try {
+
+            username = decryptUsername(username);
+            Constant.getInstance().setUserType(Constant.USER_TYPE_MANAGER);
+            String code = UUID.randomUUID().toString();
+            request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, code);
+            Map<String, Object> view = loginView(username, null,code,null,false,request, false, EasyTypeToken.LoginType.NOPASSWD);
+            view.put(Constant.VIEW_KEY_USER_TYPE, Constant.USER_TYPE_MANAGER);
+            view.put(Constant.VIEW_KEY_TOKEN, "admin-token");
+
+            SecurityUtils.getSubject().getSession().setTimeout(3600000L);
+            return view;
+        } catch (Exception e) {
+            String msg = "用户或密码错误";
+            if (StringUtils.isNotEmpty(e.getMessage())) {
+                msg = e.getMessage();
+            }
+            return error(msg);
+        }
+    }
+
+
+    /**
+     * 解密用户名
+     * @param username
+     * @return
+     */
+    public String decryptUsername(String username){
+
+        byte[] key = Base64.decode(ssoKey);
+        // 构建
+        AES aes = SecureUtil.aes(key);
+        return aes.decryptStr(username, CharsetUtil.CHARSET_UTF_8);
+    }
+
+
+
+}