Browse Source

加入图片验证码验证接口

gaodm 6 years ago
parent
commit
8088b1f588

+ 1 - 1
bi-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java

@@ -29,7 +29,7 @@ public class CommonExceptionHandler {
             log.error("【业务异常】:" + e.getMessage());
             return new ResponseEntity(resp, HttpStatus.OK);
         }
-        resp.code = -1;
+        resp.code = "-1";
         resp.msg = e.getMessage();
         log.error("【系统异常】:" + e.getMessage());
         return new ResponseEntity(resp, HttpStatus.OK);

+ 1 - 1
common/src/main/java/com/diagbot/dto/RespDTO.java

@@ -10,7 +10,7 @@ import java.io.Serializable;
 public class RespDTO<T> implements Serializable{
 
 
-    public int code = 0;
+    public String code = "0";
     public String msg = "";
     public T data;
 

+ 1 - 1
common/src/main/java/com/diagbot/exception/CommonException.java

@@ -25,7 +25,7 @@ public class CommonException extends RuntimeException {
     }
 
 
-    public int getCode() {
+    public String getCode() {
         return errorCode.getCode();
     }
 

+ 25 - 25
common/src/main/java/com/diagbot/exception/ErrorCode.java

@@ -9,38 +9,38 @@ package com.diagbot.exception;
  */
 public enum ErrorCode {
 
-    OK(0, "操作成功"),
-    FAIL(-1, "操作失败"),
-    RPC_ERROR(-2,"远程调度失败"),
-    NOT_EXISTS (00020001, "该数据不存在!"),
-    INSERT_DATA_FAILED(00020002, "数据库写入失败!"),
-    UPDATE_INFO_FAIL(00020003, "更新数据失败!"),
-    PARAM_IS_NULL(00020004, "传入的参数为空!"),
-    PARAM_IS_ERROR(00020005, "传入的参数为错误!"),
-    STATUS_IS_ERROR(00020006, "参数状态错误!"),
-    VERIFYCODE_ERROR(00020007, "图片验证码生成错误!"),
-
-    USER_NOT_FOUND(10020000,"用户不存在"),
-    USER_PASSWORD_ERROR(10020001,"密码错误"),
-    GET_TOKEN_FAIL(10020002,"获取token失败"),
-    TOKEN_IS_NOT_MATCH_USER(10020003,"请使用自己的token进行接口请求"),
-
-    SMS_SEND_ERROR(10020004, "短信发送错误!"),
-    USER_BIND_ERROR(10020005, "用户手机号已经绑定无需再次验证!"),
-    USER_UN_BIND_ERROR(10020006, "用户手机号未绑定无需解绑!"),
-
-    LOG_IS_NOT_EXIST(90020001,"该日志不存在");
-    private int code;
+    OK("0", "操作成功"),
+    FAIL("-1", "操作失败"),
+    RPC_ERROR("-2","远程调度失败"),
+    NOT_EXISTS ("00020001", "该数据不存在!"),
+    INSERT_DATA_FAILED("00020002", "数据库写入失败!"),
+    UPDATE_INFO_FAIL("00020003", "更新数据失败!"),
+    PARAM_IS_NULL("00020004", "传入的参数为空!"),
+    PARAM_IS_ERROR("00020005", "传入的参数为错误!"),
+    STATUS_IS_ERROR("00020006", "参数状态错误!"),
+    VERIFYCODE_ERROR("00020007", "图片验证码生成错误!"),
+
+    USER_NOT_FOUND("10020000","用户不存在"),
+    USER_PASSWORD_ERROR("10020001","密码错误"),
+    GET_TOKEN_FAIL("10020002","获取token失败"),
+    TOKEN_IS_NOT_MATCH_USER("10020003","请使用自己的token进行接口请求"),
+
+    SMS_SEND_ERROR("10020004", "短信发送错误!"),
+    USER_BIND_ERROR("10020005", "用户手机号已经绑定无需再次验证!"),
+    USER_UN_BIND_ERROR("10020006", "用户手机号未绑定无需解绑!"),
+
+    LOG_IS_NOT_EXIST("90020001","该日志不存在");
+    private String code;
     private String msg;
 
 
-    ErrorCode(int code, String msg) {
+    ErrorCode(String code, String msg) {
         this.code = code;
         this.msg = msg;
     }
 
 
-    public int getCode() {
+    public String getCode() {
         return code;
     }
 
@@ -48,7 +48,7 @@ public enum ErrorCode {
         return msg;
     }
 
-    public static ErrorCode codeOf(int code) {
+    public static ErrorCode codeOf(String code) {
         for (ErrorCode state : values()) {
             if (state.getCode() == code) {
                 return state;

+ 1 - 1
diagbotman-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java

@@ -29,7 +29,7 @@ public class CommonExceptionHandler {
             log.error("【业务异常】:" + e.getMessage());
             return new ResponseEntity(resp, HttpStatus.OK);
         }
-        resp.code = -1;
+        resp.code = "-1";
         resp.msg = e.getMessage();
         log.error("【系统异常】:" + e.getMessage());
         return new ResponseEntity(resp, HttpStatus.OK);

+ 1 - 1
feedback-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java

@@ -29,7 +29,7 @@ public class CommonExceptionHandler {
             log.error("【业务异常】:" + e.getMessage());
             return new ResponseEntity(resp, HttpStatus.OK);
         }
-        resp.code = -1;
+        resp.code = "-1";
         resp.msg = e.getMessage();
         log.error("【系统异常】:" + e.getMessage());
         return new ResponseEntity(resp, HttpStatus.OK);

+ 1 - 1
knowledge-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java

@@ -29,7 +29,7 @@ public class CommonExceptionHandler {
             log.error("【业务异常】:" + e.getMessage());
             return new ResponseEntity(resp, HttpStatus.OK);
         }
-        resp.code = -1;
+        resp.code = "-1";
         resp.msg = e.getMessage();
         log.error("【系统异常】:" + e.getMessage());
         return new ResponseEntity(resp, HttpStatus.OK);

+ 1 - 1
log-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java

@@ -29,7 +29,7 @@ public class CommonExceptionHandler {
             log.error("【业务异常】:" + e.getMessage());
             return new ResponseEntity(resp, HttpStatus.OK);
         }
-        resp.code = -1;
+        resp.code = "-1";
         resp.msg = e.getMessage();
         log.error("【系统异常】:" + e.getMessage());
         return new ResponseEntity(resp, HttpStatus.OK);

+ 1 - 0
user-service/src/main/java/com/diagbot/config/ResourceServerConfigurer.java

@@ -27,6 +27,7 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
                 .authorizeRequests()
                 .regexMatchers(".*swagger.*",".*v2.*",".*webjars.*","/user/login.*","/user/registry.*","/user/test.*","/druid.*","/actuator.*","/hystrix.*","/hi.*","/test.*").permitAll()
                 .antMatchers("/userver/getImgVerification").permitAll()
+                .antMatchers("/userver/verImgVerification").permitAll()
                 .antMatchers("/**").authenticated();
 //        .antMatchers("/**").permitAll();
     }

+ 1 - 0
user-service/src/main/java/com/diagbot/config/security/UrlAccessDecisionManager.java

@@ -41,6 +41,7 @@ public class UrlAccessDecisionManager implements AccessDecisionManager {
                 || matchers("/hi/**", request)
                 || matchers("/test/**", request)
                 || matchers("/userver/getImgVerification", request)
+                || matchers("/userver/verImgVerification", request)
                 || matchers("/", request)){
                     return;
                 } else {

+ 1 - 1
user-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java

@@ -29,7 +29,7 @@ public class CommonExceptionHandler {
             log.error("【业务异常】:" + e.getMessage());
             return new ResponseEntity(resp, HttpStatus.OK);
         }
-        resp.code = -1;
+        resp.code = "-1";
         resp.msg = e.getMessage();
         log.error("【系统异常】:" + e.getMessage());
         e.printStackTrace();

+ 12 - 1
user-service/src/main/java/com/diagbot/facade/VerFacade.java

@@ -6,7 +6,9 @@ import com.diagbot.enums.VisibleIdTypeEnum;
 import com.diagbot.idc.VisibleIdCreater;
 import com.diagbot.service.ImgVerService;
 import com.diagbot.service.SmsVerService;
+import com.diagbot.util.BeanUtil;
 import com.diagbot.vo.ImgVerCreatVO;
+import com.diagbot.vo.ImgVerVerVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -24,7 +26,7 @@ public class VerFacade {
 
     /**
      * 获取用户图片验证信息
-     * @return
+     * @return 图片验证码信息
      */
     public ImgVerCreatDTO getImgVerification(){
         ImgVerCreatDTO imgVerCreatDTO = new ImgVerCreatDTO();
@@ -38,5 +40,14 @@ public class VerFacade {
         return imgVerCreatDTO;
     }
 
+    /**
+     * 验证用户图片验证码是否有效
+     */
+    public Boolean verifyImgVerification(ImgVerVerVO imgVerVerVO){
+        ImgVerInfo imgVerInfo = new ImgVerInfo();
+        BeanUtil.copyProperties(imgVerVerVO, imgVerInfo);
+        return imgVerService.verifyImgVerification(imgVerInfo);
+    }
+
 
 }

+ 2 - 2
user-service/src/main/java/com/diagbot/service/impl/ImgVerServiceImpl.java

@@ -123,7 +123,7 @@ public class ImgVerServiceImpl implements ImgVerService {
         if (imgVerInfoRes == null) {
             log.info("用户图片验证信息不存在!");
             throw new CommonException(ErrorCode.NOT_EXISTS,
-                    "用户短信验证信息不存在!");
+                    "用户图片验证信息不存在!");
         }
         //判断是否是想要的对象
         if (!imgVerInfoRes.getImgId().equals(imgVerInfo.getImgId())) {
@@ -140,7 +140,7 @@ public class ImgVerServiceImpl implements ImgVerService {
         if (!DateUtil.after(imgVerInfoRes.getExpireTime(), DateUtil.now())) {
             log.info("图片验证码已过期,请重新获取!过期时间:{}", imgVerInfoRes.getExpireTime());
             throw new CommonException(ErrorCode.PARAM_IS_ERROR,
-                    "图片已过期,请重新获取!");
+                    "图片验证码已过期,请重新获取!");
         }
         return true;
     }

+ 20 - 0
user-service/src/main/java/com/diagbot/vo/ImgVerVerVO.java

@@ -0,0 +1,20 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/**
+ * @Description: 图片验证码验证输入信息
+ * @author: gaodm
+ * @time: 2018/9/3 15:38
+ */
+@Getter
+@Setter
+public class ImgVerVerVO {
+    //图片验证码唯一标志
+    private String imgId;
+    //验证码
+    private String code;
+}

+ 19 - 1
user-service/src/main/java/com/diagbot/web/VerController.java

@@ -4,9 +4,11 @@ import com.diagbot.annotation.SysLogger;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.facade.VerFacade;
 import com.diagbot.vo.ImgVerCreatVO;
+import com.diagbot.vo.ImgVerVerVO;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -21,10 +23,26 @@ public class VerController {
     @Autowired
     private VerFacade verFacade;
 
-    @ApiOperation(value = "获取图片验证码", notes = "获取图片验证码包括包括系统验证用的ID和图片信息")
+    /**
+     * 获取图片验证码
+     * @return 图片验证码包括图片验证码唯一标志和图片信息
+     */
+    @ApiOperation(value = "获取图片验证码", notes = "获取图片验证码包括图片验证码唯一标志和图片信息")
     @GetMapping("/getImgVerification")
     @SysLogger("getImgVerification")
     public RespDTO getImgVerification(){
         return   RespDTO.onSuc(verFacade.getImgVerification());
     }
+
+    /**
+     * 验证图片验证码信息
+     * @param imgVerVerVO 验证图片验证码所需参数
+     * @return
+     */
+    @ApiOperation(value = "验证图片验证码", notes = "图片验证码唯一标志后和验证码不能为空")
+    @PostMapping("/verImgVerification")
+    @SysLogger("verImgVerification")
+    public RespDTO verImgVerification(ImgVerVerVO imgVerVerVO){
+        return   RespDTO.onSuc(verFacade.verifyImgVerification(imgVerVerVO));
+    }
 }