he2802 преди 3 години
родител
ревизия
551b09f9c7

+ 18 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/system/SysLoginController.java

@@ -15,6 +15,7 @@ import com.zhongzheng.framework.web.service.TokenService;
 import com.zhongzheng.modules.system.service.ISysMenuService;
 import com.zhongzheng.modules.system.service.ISysTenantService;
 import com.zhongzheng.modules.system.vo.SysTenantVo;
+import com.zhongzheng.modules.user.bo.UserBusinessLoginBo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -53,6 +54,23 @@ public class SysLoginController
     @Autowired
     private ISysTenantService iSysTenantService;
 
+    /**
+     * 登录方法
+     *
+     * @param loginBody 登录信息
+     * @return 结果
+     */
+    @ApiOperation("业务系统获取登录token")
+    @GetMapping("/businessToken")
+    public AjaxResult businessToken(UserBusinessLoginBo loginBody)
+    {
+        AjaxResult ajax = AjaxResult.success();
+        // 生成令牌
+        String token = loginService.businessLogin(loginBody);
+        ajax.put(Constants.TOKEN, token);
+        return ajax;
+    }
+
     /**
      * 登录方法
      *

+ 1 - 1
zhongzheng-framework/src/main/java/com/zhongzheng/framework/config/SecurityConfig.java

@@ -110,7 +110,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 验证码captchaImage 允许匿名访问
-                .antMatchers("/login", "/captchaImage", "/testLogin","/wx/pay/callback","/gzh_login","/check_pc_login","/pc_login_url","/scan_code").anonymous()
+                .antMatchers("/login", "/captchaImage", "/testLogin","/wx/pay/callback","/gzh_login","/check_pc_login","/pc_login_url","/scan_code","/businessToken").anonymous()
                 .antMatchers("/aliyun/oss/callback").anonymous()
                 .antMatchers(
                         HttpMethod.GET,

+ 47 - 2
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/SysLoginService.java

@@ -3,11 +3,15 @@ package com.zhongzheng.framework.web.service;
 import javax.annotation.Resource;
 
 
+import cn.hutool.core.lang.Validator;
 import com.zhongzheng.common.core.domain.entity.SysUser;
+import com.zhongzheng.common.core.domain.model.LoginBody;
+import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.framework.manager.factory.AsyncFactory;
 import com.zhongzheng.modules.system.service.ISysUserService;
 import com.zhongzheng.common.utils.AES;
 import com.zhongzheng.framework.manager.factory.AsyncFactory;
+import com.zhongzheng.modules.user.bo.UserBusinessLoginBo;
 import org.apache.commons.compress.utils.IOUtils;
 import org.bouncycastle.jcajce.provider.asymmetric.rsa.RSAUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -49,6 +53,8 @@ public class SysLoginService
     @Autowired
     private ISysUserService iSysUserService;
 
+
+
     /**
      * 登录验证
      *
@@ -90,8 +96,6 @@ public class SysLoginService
             if(password.length()>20){
                 password = AES.decrypt(password,rsaPrivate);
             }
-            System.out.println(password);
-            System.out.println("密码");
             authentication = authenticationManager
                     .authenticate(new UsernamePasswordAuthenticationToken(username, password));
         }
@@ -116,6 +120,47 @@ public class SysLoginService
         return tokenService.createToken(loginUser);
     }
 
+    public String businessLogin(UserBusinessLoginBo loginBody)
+    {
+        String password;
+        if(Validator.isEmpty(loginBody.getPwd())){
+            throw new CustomException("密码不能为空");
+        }
+        try
+        {
+        String rsaPrivate = null;
+        try {
+            InputStream certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("config/pri.key");
+            rsaPrivate = AES.getStringByInputStream_1(certStream);
+            certStream.close();
+        } catch (Exception e) {
+            throw new CustomException("参数错误"+e.getMessage());
+        }
+            password = AES.decrypt(loginBody.getPwd(),rsaPrivate);
+            String[] param = password.split("#");
+            if(param.length!=2||!"test".equals(param[0])){
+                throw new CustomException("参数内容非法");
+            }
+            Long nowTime = DateUtils.getNowTime();
+            Long paramTime = Long.valueOf(param[1]);
+            if(Validator.isEmpty(paramTime)||Math.abs(paramTime.longValue()-nowTime.longValue())>30){
+                throw new CustomException("参数内容错误");
+            }
+        }
+        catch (Exception e)
+        {
+            throw new CustomException(e.getMessage());
+        }
+        String username = "admin";
+        LoginUser loginUser = new LoginUser();
+        //普通系统用户
+        SysUser user = iSysUserService.selectUserByUserName(username);
+        user = iSysUserService.updateLoginTimeIp(user.getUserId());
+        loginUser.setUser(user);
+        // 生成token
+        return tokenService.createToken(loginUser);
+    }
+
    /* public String wx_login(String username)
     {
         LoginUser loginUser = (LoginUser) authentication.getPrincipal();

+ 24 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/bo/UserBusinessLoginBo.java

@@ -0,0 +1,24 @@
+package com.zhongzheng.modules.user.bo;
+
+import com.zhongzheng.common.annotation.Excel;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+
+/**
+ * 客户端用户编辑对象 user
+ *
+ * @author ruoyi
+ * @date 2021-06-08
+ */
+@Data
+@ApiModel("客户端用户编辑对象")
+public class UserBusinessLoginBo {
+
+
+    /** 密码 */
+    @ApiModelProperty("密码")
+    private String pwd;
+
+}