Просмотр исходного кода

Merge remote-tracking branch 'origin/dev' into dev

lengfaqiang 2 лет назад
Родитель
Сommit
dbb10cbad5

+ 48 - 1
sckw-auth/src/main/java/com/sckw/auth/controller/AuthController.java

@@ -2,13 +2,17 @@ package com.sckw.auth.controller;
 
 import com.sckw.auth.model.vo.req.*;
 import com.sckw.auth.service.IAuthService;
+import com.sckw.core.common.enums.enums.DictEnum;
 import com.sckw.core.exception.SystemException;
+import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.enums.LoginMethodEnum;
 import com.sckw.core.model.enums.SystemTypeEnum;
 import com.sckw.core.utils.RegularUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.redis.constant.RedisConstant;
+import com.sckw.redis.utils.RedissonUtils;
 import jakarta.validation.Valid;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -53,6 +57,34 @@ public class AuthController {
         return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.GLOBAL_EXCEPTION_MESSAGE);
     }
 
+    @PostMapping("/smsLogin")
+    public HttpResult smsAuth(@RequestHeader(name = "System-Type") int systemType,
+                            @RequestHeader(name = "Client-Type") String clientType,
+                            @RequestBody @Valid LoginBase loginBase) {
+        loginBase.setSystemType(systemType);
+        loginBase.setClientType(clientType);
+        loginBase.setLoginMethod(LoginMethodEnum.SMS.getValue());
+
+        /**参数校验**/
+        HttpResult result = checkParams(loginBase);
+        if (result.getCode() != HttpStatus.SUCCESS_CODE) {
+            return result;
+        }
+
+        /**运营端/企业端登录(PC/APP)**/
+        if (loginBase.getSystemType() == SystemTypeEnum.MANAGE.getCode()
+                || loginBase.getSystemType() == SystemTypeEnum.COMPANY.getCode()) {
+            return authService.commonAuth(loginBase);
+        }
+
+        /**司机端**/
+        if (loginBase.getSystemType() == SystemTypeEnum.DRIVER.getCode()) {
+            return authService.driverAuth(loginBase);
+        }
+
+        return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.GLOBAL_EXCEPTION_MESSAGE);
+    }
+
     /**
      * @param
      * @return
@@ -73,12 +105,27 @@ public class AuthController {
         if (params.getLoginMethod() == LoginMethodEnum.ORDINARY.getValue() && StringUtils.isBlank(params.getPassword())) {
             return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, "请输入您的密码!");
         }
+
         if (params.getLoginMethod() == LoginMethodEnum.SMS.getValue() && !RegularUtils.matchs(RegularUtils.PHONE_REG, params.getAccount())) {
             return HttpResult.error(HttpStatus.PARAMETERS_PATTERN_ERROR_CODE, "手机号格式不正确,请检查并重新输入!");
         }
         if (params.getLoginMethod() == LoginMethodEnum.SMS.getValue() && StringUtils.isBlank(params.getCaptcha())) {
-            return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, "请输入您的验证码!");
+            return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, "请输入您的验证码!");
+        }
+        String key = StringUtils.format(RedisConstant.MESSAGE_SMS_VERIFY_CODE_VALUE_KEY, DictEnum.SMS_LOGIN.getValue(), params.getAccount());
+
+        RedissonUtils.putString(key, params.getCaptcha(), RedisConstant.SMS_VERIFY_CODE_VALID_TIME);
+        String captcha = RedissonUtils.getString(key);
+        if (params.getLoginMethod() == LoginMethodEnum.SMS.getValue() && StringUtils.isBlank(captcha)) {
+            return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, "验证码已过期,请重新获取!");
         }
+        if (params.getLoginMethod() == LoginMethodEnum.SMS.getValue() && StringUtils.isBlank(captcha)) {
+            return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, "验证码已过期,请重新获取!");
+        }
+        if (params.getLoginMethod() == LoginMethodEnum.SMS.getValue() && !captcha.equals(params.getCaptcha())) {
+            return HttpResult.error(HttpStatus.UN_LOGIN_CODE, "验证码不正确,请检查并重新输入!");
+        }
+
         return HttpResult.ok();
     }
     /**--------------------------------------------------------------------------------------------------------------**/

+ 18 - 11
sckw-auth/src/main/java/com/sckw/auth/service/impl/AuthServiceImpl.java

@@ -8,6 +8,8 @@ import com.sckw.auth.model.vo.res.EntInfoResVo;
 import com.sckw.auth.model.vo.res.LoginResVo;
 import com.sckw.auth.model.vo.res.LoginResVo1;
 import com.sckw.auth.util.AsyncFactory;
+import com.sckw.core.model.enums.ClientTypeEnum;
+import com.sckw.core.model.enums.LoginMethodEnum;
 import com.sckw.core.model.enums.SystemTypeEnum;
 import com.sckw.core.utils.*;
 import com.sckw.core.web.model.EntCertificateInfo;
@@ -372,11 +374,12 @@ public class AuthServiceImpl implements IAuthService {
         if (driver == null) {
             return HttpResult.error(HttpStatus.QUERY_FAIL_CODE, "账号不存在,请检查并重新输入!");
         }
-        if (!PasswordUtils.validatePassword(loginBase.getPassword(), driver.getPassword())) {
+        if (loginBase.getLoginMethod() == LoginMethodEnum.ORDINARY.getValue()
+                && !PasswordUtils.validatePassword(loginBase.getPassword(), driver.getPassword())) {
             return HttpResult.error(HttpStatus.CODE_10301, "密码不正确,请检查并重新输入!");
         }
         if (driver.getStatus() == Global.YES) {
-            return HttpResult.error(HttpStatus.CODE_10301, "您的账号已冻结,如需帮助,请致电平台客服:400-803-6377!");
+            return HttpResult.error(HttpStatus.CODE_10301, "您的账号已冻结,如需帮助,请致电平台客服!");
         }
         //企业信息
         REnterpriseVo enterprise = systemService.queryEntDetails(driver.getEntId());
@@ -421,11 +424,12 @@ public class AuthServiceImpl implements IAuthService {
         if (user == null) {
             return HttpResult.error(HttpStatus.QUERY_FAIL_CODE, "账号不存在,请检查并重新输入!");
         }
-        if (!PasswordUtils.validatePassword(loginBase.getPassword(), user.getPassword())) {
+        if (loginBase.getLoginMethod() == LoginMethodEnum.ORDINARY.getValue()
+                && !PasswordUtils.validatePassword(loginBase.getPassword(), user.getPassword())) {
             return HttpResult.error(HttpStatus.CODE_10301, "密码不正确,请检查并重新输入!");
         }
         if (user.getStatus() == Global.YES) {
-            return HttpResult.error(HttpStatus.CODE_10301, "您的账号已冻结,如需帮助,请致电平台客服:400-803-6377!");
+            return HttpResult.error(HttpStatus.CODE_10301, "您的账号已冻结,如需帮助,请致电平台客服!");
         }
         //企业信息
         REnterpriseVo enterprise = systemService.queryEntDetails(user.getEntId());
@@ -433,7 +437,7 @@ public class AuthServiceImpl implements IAuthService {
             return HttpResult.error(HttpStatus.QUERY_FAIL_CODE, "账号没有归属企业,请检查并重新输入!");
         }
         if (enterprise != null && enterprise.getStatus() == Global.YES) {
-            return HttpResult.error(HttpStatus.QUERY_FAIL_CODE, "企业已冻结,如需帮助,请致电平台客服:400-803-6377!");
+            return HttpResult.error(HttpStatus.QUERY_FAIL_CODE, "企业已冻结,如需帮助,请致电平台客服!");
         }
 
         /**生成token**/
@@ -457,15 +461,17 @@ public class AuthServiceImpl implements IAuthService {
         loginRes.setRoleName(user.getRoleName());
         loginRes.setClientId(user.getClientId());
         loginRes.setEntId(user.getEntId());
-        loginRes.setFirmName(enterprise == null ? enterprise.getFirmName() : null);
-        loginRes.setApproval(enterprise == null ? enterprise.getApproval() : null);
-        loginRes.setEntTypeNames(enterprise == null ? enterprise.getEntTypeNames() : null);
+        loginRes.setFirmName(enterprise != null ? enterprise.getFirmName() : null);
+        loginRes.setApproval(enterprise != null ? enterprise.getApproval() : null);
+        loginRes.setEntTypeNames(enterprise != null ? enterprise.getEntTypeNames() : null);
         loginRes.setClientType(loginBase.getClientType());
         loginRes.setSystemType(loginBase.getSystemType());
         loginRes.setToken(token);
         return HttpResult.ok(loginRes);
     }
 
+
+
     static class AsyncProcess1 implements Runnable {
         private final LoginBase loginBase;
 
@@ -511,7 +517,7 @@ public class AuthServiceImpl implements IAuthService {
             LoginEntInfo loginEntInfo = new LoginEntInfo();
             BeanUtils.copyProperties(ent, loginEntInfo);
             String key = Global.REDIS_ENTERPRISE_PREFIX + ent.getId();
-            RedissonUtils.putString(key, JSON.toJSONString(loginEntInfo), Global.PC_TOKEN_EXPIRE);
+            RedissonUtils.putString(key, JSON.toJSONString(loginEntInfo), Global.APP_TOKEN_EXPIRE);
         }
 
         /**
@@ -537,7 +543,7 @@ public class AuthServiceImpl implements IAuthService {
             loginUserInfo.setEntName(enterprise != null ? enterprise.getFirmName() : null);
             loginUserInfo.setClientType(loginBase.getClientType());
             String key = Global.getFullUserLoginKey(loginUserInfo.getSystemType(), loginUserInfo.getId(), loginBase.getClientType());
-            RedissonUtils.putString(key, JSON.toJSONString(loginUserInfo), Global.PC_TOKEN_EXPIRE);
+            RedissonUtils.putString(key, JSON.toJSONString(loginUserInfo), Global.APP_TOKEN_EXPIRE);
         }
 
         /**
@@ -563,7 +569,8 @@ public class AuthServiceImpl implements IAuthService {
             loginUserInfo.setEntId(user.getEntId());
             loginUserInfo.setEntName(enterprise != null ? enterprise.getFirmName() : null);
             String key = Global.getFullUserLoginKey(loginUserInfo.getSystemType(), loginUserInfo.getId(), loginBase.getClientType());
-            RedissonUtils.putString(key, JSON.toJSONString(loginUserInfo), Global.PC_TOKEN_EXPIRE);
+            RedissonUtils.putString(key, JSON.toJSONString(loginUserInfo),
+                    loginBase.getClientType().equals(ClientTypeEnum.pc.getValue()) ? Global.PC_TOKEN_EXPIRE : Global.APP_TOKEN_EXPIRE);
 
             //存缓存请求地址
             SaveMenusToCache(user);

+ 1 - 1
sckw-common/sckw-common-core/src/main/java/com/sckw/core/utils/PasswordUtils.java

@@ -122,7 +122,7 @@ public class PasswordUtils {
 
     public static void main(String[] args) {
 
-        String password = PasswordUtils.entryptPassword(PasswordUtils.md5("18000000000"));
+        String password = PasswordUtils.entryptPassword(PasswordUtils.md5("17358629955"));
         String md5 = PasswordUtils.md5("123456");
         System.out.println(password);
         System.out.println(md5);

+ 1 - 1
sckw-common/sckw-common-core/src/main/java/com/sckw/core/utils/StringUtils.java

@@ -718,7 +718,7 @@ public class StringUtils {
      * @param args
      * @return
      */
-    public static String getKey(String prefix, String args) {
+    public static String format(String prefix, Object... args) {
         return String.format(prefix, args);
     }
 

+ 3 - 6
sckw-modules/sckw-message/src/main/java/com/sckw/message/service/SmsService.java

@@ -5,6 +5,7 @@ import com.sckw.core.common.enums.enums.DictEnum;
 import com.sckw.core.common.enums.enums.DictTypeEnum;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.utils.NumberUtils;
+import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.message.model.vo.req.SendSmsVerifyCoderReqVO;
 import com.sckw.redis.constant.RedisConstant;
@@ -15,7 +16,6 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.cloud.stream.function.StreamBridge;
 import org.springframework.stereotype.Service;
-
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
@@ -45,8 +45,8 @@ public class SmsService {
             throw new BusinessException("非法短信类型!");
         }
         String phone = param.getPhone();
-        String messageSmsVerifyCodeKey = getMessageSmsVerifyCodeKey(type, phone);
-        if (Boolean.TRUE.equals(RedissonUtils.exists(messageSmsVerifyCodeKey))) {
+        String key = StringUtils.format(RedisConstant.MESSAGE_SMS_VERIFY_CODE_VALUE_KEY, type, phone);
+        if (Boolean.TRUE.equals(RedissonUtils.exists(key))) {
             throw new BusinessException("请勿频繁获取短信验证码!");
         }
         Map<String, Object> params = new HashMap<>();
@@ -57,7 +57,4 @@ public class SmsService {
         streamBridge.send("sckw-sms", JSON.toJSONString(sckwSms));
     }
 
-    private String getMessageSmsVerifyCodeKey(String type, String phone) {
-        return String.format(RedisConstant.MESSAGE_SMS_VERIFY_CODE_VALUE_KEY, type, phone);
-    }
 }