From b2e87d8672d2cb39847ab065901be982ef6fcbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E9=A3=9E=E4=BA=91?= <1941783199@qq.com> Date: Sun, 27 Sep 2020 19:43:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BE=9D=E8=B5=96=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hrauth/controller/UserLoginController.java | 14 ++++++++++---- .../service/impl/UserLoginServiceImpl.java | 2 +- .../daqing/financial/hrauth/util/JwtUtil.java | 18 +++++++++--------- .../mapper/hrmsauth/UserLoginMapper.xml | 8 ++++---- .../com/daqing/framework/util/Md5Util.java | 4 ++++ .../domain/hrms/request/LoginRequest.java | 2 ++ 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java index 4a91a547..80c2720e 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java @@ -42,11 +42,17 @@ public class UserLoginController { @PostMapping(value = "/login") @ApiOperation(value = "用户登录") public ResponseResult login( - @RequestBody LoginRequest loginRequest - /*@RequestParam("password") String password, @RequestParam("phone") String phone*/){ - /*LoginRequest loginRequest = new LoginRequest(); + //@RequestBody LoginRequest loginRequest + @RequestParam("password") String password, @RequestParam("phone") String phone, + @RequestParam("type")int type, @RequestParam("wechatId") String wechatId, + @RequestParam("tenDayEffective") int tenDayEffective + ){ + LoginRequest loginRequest = new LoginRequest(); + loginRequest.setTenDayEffective(tenDayEffective); + loginRequest.setType(type); + loginRequest.setWechatId(wechatId); loginRequest.setPassword(password); - loginRequest.setPhone(phone);*/ + loginRequest.setPhone(phone); return userLoginService.login(loginRequest); } } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java index 0770b129..33d3e1de 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java @@ -90,7 +90,7 @@ public class UserLoginServiceImpl extends ServiceImpl return ResponseResult.FAIL(CommonCode.USER_IS_NOT_EXIST.code(), CommonCode.USER_IS_NOT_EXIST.message()); } String newPassword = Md5Util.md5(loginRequest.getPassword()+userEntity.getId()); - if(!newPassword.equals(loginRequest.getPassword())){ + if(!newPassword.equals(userEntity.getPassword())){ return ResponseResult.FAIL(CommonCode.PASSWORD_IS_ERROR.code(), CommonCode.PASSWORD_IS_ERROR.message()); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/JwtUtil.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/JwtUtil.java index 1502c23f..d38eac5d 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/JwtUtil.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/JwtUtil.java @@ -1,11 +1,8 @@ package com.daqing.financial.hrauth.util; -import com.auth0.jwt.JWT; -import com.auth0.jwt.algorithms.Algorithm; -import com.daqing.financial.hrauth.SpringContextHolder; +import com.daqing.framework.util.Md5Util; -import java.util.Date; import java.util.Set; /** @@ -16,7 +13,7 @@ import java.util.Set; */ public class JwtUtil { - private final static Algorithm algorithm = SpringContextHolder.getBean("algorithm", Algorithm.class); + //private final static Algorithm algorithm = SpringContextHolder.getBean("algorithm", Algorithm.class); //private final static OdcProperties properties = SpringContextHolder.getBean("odcProperties", OdcProperties.class); @@ -27,16 +24,19 @@ public class JwtUtil { * @param timeout; 单位是秒 */ public static String createJwtToken(Long userId, long timeout) { - return JWT.create() + String token = Md5Util.md5(userId+timeout+"dq"); + RedisUtil.setEx("dq:token:"+userId, token, timeout); + return token; + /*return JWT.create() .withClaim("member", userId) .withExpiresAt(new Date(System.currentTimeMillis() + timeout * 1000)) - .sign(algorithm); + .sign(algorithm);*/ } /** * token正确且有效,则返回userId */ - public static Long verifyToken(String token) { +/* public static Long verifyToken(String token) { try { String noBearerToken = token.replaceFirst("Bearer ", ""); Long userId = JWT.require(algorithm) @@ -52,7 +52,7 @@ public class JwtUtil { return null; } return null; - } + }*/ public static String getRedisKey(Long userId, String token) { return String.format("dq:token:%d:%s", userId, token); diff --git a/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml b/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml index a1e90a4b..f0d67530 100644 --- a/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml +++ b/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml @@ -16,11 +16,11 @@ diff --git a/dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java b/dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java index c2fa7837..ec639040 100644 --- a/dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java +++ b/dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java @@ -17,4 +17,8 @@ public class Md5Util { } return DigestUtils.md5DigestAsHex(str.getBytes()); } + + public static void main(String[] args) { + System.out.printf(md5("1234561")); + } } diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/LoginRequest.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/LoginRequest.java index a8ba2434..af330c96 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/LoginRequest.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/LoginRequest.java @@ -6,6 +6,8 @@ import lombok.Data; @Data public class LoginRequest { + private int id; + @ApiModelProperty(value = "手机号码") private String phone;