Bladeren bron

fixed login

zero 1 jaar geleden
bovenliggende
commit
cce3b83a05

+ 1 - 1
src/main/java/com/example/xiaoshiweixinback/business/common/Response.java

@@ -72,7 +72,7 @@ public class Response {
 
     public static Response error(String message) {
         Response response = new Response();
-        response.setCode(ResponseEnum.ERROR.getCode());
+        response.setCode(ResponseEnum.SYSTEM_ERROR.getCode());
         response.setData(Boolean.FALSE);
         response.setMessage(message);
         return response;

+ 0 - 110
src/main/java/com/example/xiaoshiweixinback/business/common/base/Constants.java

@@ -1,110 +0,0 @@
-package com.example.xiaoshiweixinback.business.common.base;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class Constants {
-
-    public static final String API_XIAO_SHI_WXBACK = "/api/xiaoshi/weixinback";
-    public static final String ADMIN_USERNAME = "admin";
-
-    public static final Integer PATENT_CLASS_NUMBER_IPC = 1;
-    public static final Integer PATENT_CLASS_NUMBER_CPC = 2;
-    public static final Integer PATENT_CLASS_NUMBER_UPC = 3;
-    public static final Integer PATENT_CLASS_NUMBER_LOC = 4;
-    public static final Integer MAX_IMPORT_TASK_COUNT=5;
-    public static final  Integer IMPORT_PATENT_TO=1;
-    /**
-     * 分隔符-竖线
-     */
-    public static final String SEPARATOR_VERTICAL_BAR = " | ";
-
-    /**
-     * 系统字段类型-查询检索
-     */
-    public static final String SYSTEM_FIELD_QUERY = "query";
-
-    /**
-     * 系统字段类型-专利导出
-     */
-    public static final String SYSTEM_FIELD_EXPORT = "export";
-
-    /**
-     * 系统字段类型-专利列表
-     */
-    public static final String SYSTEM_FIELD_PATENT_LIST = "list";
-
-    /**
-     * 系统字段类型-专题库字段
-     */
-    public static final String SYSTEM_FIELD_PROJECT = "project";
-
-    /**
-     * 专题库导入专利任务名称
-     */
-    public static final Integer TASK_IMPORT_PATENT = 1;
-
-    /**
-     * 专利说明书导入任务名称
-     */
-    public static final Integer TASK_IMPORT_PATENT_INSTRUCTION = 3;
-
-    /**
-     * 专利导出任务名称
-     */
-    public static final Integer TASK_EXPORT_PATENT = 2;
-
-    /**
-     * 日期位移值
-     */
-    public static final Map<String, Integer> DATE_OFFSET = new HashMap<String, Integer>() {{
-        put("月", -1);
-        put("季", -3);
-        put("半年", -6);
-        put("年", -12);
-        put("2年", -24);
-        put("3年", -36);
-        put("5年", -60);
-    }};
-
-    /**
-     * 专利类型
-     */
-    public static final String PATENT_TYPE = "PATENT_TYPE";
-
-    /**
-     * 机构类型
-     */
-    public static final String ORGAN_TYPE = "ORGAN_TYPE";
-
-    /**
-     * 许可人/被许可人
-     */
-    public static final String LICENSOR_TYPE = "LICENSOR_TYPE";
-
-    /**
-     * 简单法律状态
-     */
-    public static final String PATENT_SIMPLE_STATUS = "PATENT_SIMPLE_STATUS";
-
-    /**
-     * 国家
-     */
-    public static final String COUNTRIES = "COUNTRIES";
-
-    /**
-     * 法律状态
-     */
-    public static final String PATENT_STATUS = "PATENT_STATUS";
-
-    /**
-     * 企业应用场景
-     */
-    public static final String ENTERPRISE_APPLICATION_SCENARIO = "ENTERPRISE_APPLICATION_SCENARIO";
-
-    /**
-     * 调查类型
-     */
-    public static final String INVESTIGATION_TYPE = "INVESTIGATION_TYPE";
-
-}

+ 5 - 6
src/main/java/com/example/xiaoshiweixinback/business/exception/BusinessException.java

@@ -1,25 +1,27 @@
 package com.example.xiaoshiweixinback.business.exception;
 
 
+import lombok.Getter;
+
 /**
  * @ClassName
  * @Description 业务异常
- * @Author 陈凯裕
- * @Date 2022/6/27 18:02
  * @Version TODO
  **/
+@Getter
 public class BusinessException extends RuntimeException {
 
-	private static final long serialVersionUID = 3200004685293133433L;
 	private String errorCode;// 异常代码
 	private String errorMessage;// 异常信息
 
 	public BusinessException(String errorCode, String errorMessage) {
+		super(errorMessage);
 		this.errorCode = errorCode;
 		this.errorMessage = errorMessage;
 	}
 
 	public BusinessException(ExceptionEnum e) {
+		super(e.getMessage());
 		this.errorMessage = e.getMessage();
 		this.errorCode = e.getCode();
 	}
@@ -41,8 +43,5 @@ public class BusinessException extends RuntimeException {
 		this.errorMessage = errorMessage;
 	}
 
-	public static long getSerialversionuid() {
-		return serialVersionUID;
-	}
 
 }

+ 5 - 2
src/main/java/com/example/xiaoshiweixinback/business/exception/ExceptionEnum.java

@@ -1,5 +1,8 @@
 package com.example.xiaoshiweixinback.business.exception;
 
+import lombok.Getter;
+
+@Getter
 public enum ExceptionEnum {
 
     /*APP端 100000-300000*/
@@ -7,9 +10,9 @@ public enum ExceptionEnum {
     SYSTEM_ERROR("999999", "系统异常"),
     PARAMETER_VERIFICATION_ERROR("000001", "数据参数校验异常"),
     PHONE_FORMAT_ERROR("000002","手机号格式错误"),
-    CODE_WRONG("10002","验证码错误"),
-
 
+    VERIFY_CODE("10001", "校验码失效"),
+    CODE_WRONG("10002","验证码错误"),
     INIT_GENERICITY_BEAN_ERROR("10003","泛型实例化异常"),
     THE_PHONE_CANNOT_BE_EXIST("10004","手机号已存在"),
     THE_CODE_IS_NOT_NULL("10006","验证码不能为空");

+ 2 - 1
src/main/java/com/example/xiaoshiweixinback/business/exception/GlobalExceptionHandler.java

@@ -3,6 +3,7 @@ package com.example.xiaoshiweixinback.business.exception;
 import com.example.xiaoshiweixinback.business.common.log.LogHelper;
 import com.example.xiaoshiweixinback.business.common.response.ResponseData;
 import jakarta.servlet.http.HttpServletResponse;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.converter.HttpMessageNotReadableException;
@@ -11,7 +12,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseStatus;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
 
-
+@Slf4j
 @RestControllerAdvice
 public class GlobalExceptionHandler {
 

+ 15 - 0
src/main/java/com/example/xiaoshiweixinback/business/exception/XiaoShiException.java

@@ -0,0 +1,15 @@
+package com.example.xiaoshiweixinback.business.exception;
+
+/**
+ * 整个项目通用异常类
+ *
+ * @Author chenyu
+ * @Date 2023/3/7
+ */
+public class XiaoShiException extends RuntimeException {
+
+    public XiaoShiException(String message) {
+        super(message);
+    }
+
+}

+ 9 - 7
src/main/java/com/example/xiaoshiweixinback/controller/LoginController.java

@@ -1,8 +1,8 @@
 package com.example.xiaoshiweixinback.controller;
 
 
+import com.example.xiaoshiweixinback.business.common.Constants;
 import com.example.xiaoshiweixinback.business.common.Response;
-import com.example.xiaoshiweixinback.business.common.base.Constants;
 import com.example.xiaoshiweixinback.entity.dto.person.*;
 import com.example.xiaoshiweixinback.entity.vo.person.LoginByWxVO;
 import com.example.xiaoshiweixinback.entity.vo.person.LoginVO;
@@ -21,7 +21,7 @@ import java.util.Map;
  *
  * @author: 高昌奎
  */
-@RequestMapping(Constants.API_XIAO_SHI_WXBACK + "/account")
+@RequestMapping(Constants.XIAOSHI_WEIXINBACK + "/account")
 @RestController
 public class LoginController {
 
@@ -55,11 +55,13 @@ public class LoginController {
     @Operation(summary = "发送验证码")
     @PostMapping("/sendCode")
     public Response sendCode(@RequestBody @Valid SendCodeDTO vo) {
-        boolean b = loginService.sendCode(vo);
-        if (!b) {
-            return Response.error("发送验证码失败");
+        boolean b = false;
+        try {
+            b = loginService.sendCode(vo);
+        } catch (Exception e) {
+            return Response.error(e.getMessage());
         }
-        return Response.success("发送验证码成功");
+        return Response.success(b);
     }
 
     @PostMapping("/verifyCode")
@@ -69,7 +71,7 @@ public class LoginController {
         try {
             map = loginService.verifyCode(vo);
         } catch (Exception e) {
-            return Response.success(e.getMessage());
+            return Response.error(e.getMessage());
         }
         return Response.success(map);
     }

+ 1 - 1
src/main/java/com/example/xiaoshiweixinback/entity/vo/person/LoginByWxVO.java

@@ -8,7 +8,7 @@ public class LoginByWxVO {
 
     private String userName;
 
-    private String phone;
+    private String phoneNum;
 
     private String name;
 

+ 13 - 8
src/main/java/com/example/xiaoshiweixinback/service/LoginService.java

@@ -178,7 +178,7 @@ public class LoginService {
 
                     wxVO.setIfFirst(true);
                 }
-                wxVO.setPhone(phoneNumber);
+                wxVO.setPhoneNum(phoneNumber);
                 wxVO.setName(name);
                 wxVO.setFileGuid(fileGuid);
             }
@@ -190,22 +190,27 @@ public class LoginService {
     }
 
     public boolean sendCode(SendCodeDTO vo) {
+        boolean flag = false;
         if (!RegexUtil.isPhoneLegal(vo.getPhoneNum())) {
             throw new BusinessException(ExceptionEnum.PHONE_FORMAT_ERROR);
         }
-        String checkCode = redisService.get(AppCacheKeyUtil.getCheckCode(vo.getPhoneNum())).toString();
-        if (ToolUtil.isNotEmpty(checkCode) && ToolUtil.equals(checkCode,vo.getCheckCode())) {
+        Object checkCode = redisService.get(AppCacheKeyUtil.getCheckCode(vo.getPhoneNum()));
+        if (ToolUtil.isEmpty(checkCode)) {
+            throw new BusinessException(ExceptionEnum.VERIFY_CODE);
+        }
+        if (ToolUtil.isNotEmpty(checkCode.toString()) && ToolUtil.equals(checkCode.toString(),vo.getCheckCode())) {
+            //删除校验码
+            redisService.delete(AppCacheKeyUtil.getCheckCode(vo.getPhoneNum()));
             //生成验证码
             String random = RandomUtil.getSixRandom();
-            //手机号和验证码放进缓存 设置过期时间15m
+            //手机号和验证码放进缓存 设置过期时间5m
             redisService. set(AppCacheKeyUtil.getLoginMessageCode(vo.getPhoneNum()), random);
             redisService.expire(AppCacheKeyUtil.getLoginMessageCode(vo.getPhoneNum()), CacheTTLEnum.FIVE_MINUTE);
             //发送短信
 //        smsService.sendMessage(vo.getPhoneNo(), random);
-            return true;
-        } else {
-            return false;
+            flag = true;
         }
+        return flag;
     }
 
     /**
@@ -227,7 +232,7 @@ public class LoginService {
         result.put("captcha", ImgUtil.toBase64DataUri(captcha.getImage(), "png"));
         result.put("uuid", uuid);
         //4.将验证码存放到Redis里面并设置过期时间为 60 单位:秒 KEY值格式为: 验证码:UUID  VALUE值为:验证码生成工具所生成的验证码
-//        redisUtil.setEx(AppCacheKeyUtil.getCheckCode(vo.getPhoneNum()), captcha.getCode(), 60, TimeUnit.SECONDS);
+        redisService.set(AppCacheKeyUtil.getCheckCode(vo.getPhoneNum()), captcha.getCode());
         return result;
     }