tangbin пре 10 месеци
родитељ
комит
84046bdc21

+ 9 - 11
yezhu-api/src/main/java/com/kioor/user/controller/ApiRegisterController.java

@@ -10,6 +10,7 @@ package com.kioor.user.controller;
 
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.crypto.digest.DigestUtil;
+import com.kioor.common.exception.ErrorCode;
 import com.kioor.common.redis.RedisKeys;
 import com.kioor.common.redis.RedisUtils;
 import com.kioor.common.service.SysSmsService;
@@ -21,13 +22,12 @@ import com.kioor.user.service.UserService;
 import io.micrometer.common.util.StringUtils;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.Parameters;
+import io.swagger.v3.oas.annotations.media.Schema;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.Date;
-import java.util.Map;
 
 /**
  * 注册接口
@@ -50,24 +50,22 @@ public class ApiRegisterController {
      */
     @PostMapping("sendCode")
     @Operation(summary = "发送验证码")
-    @Parameters({
-            @Parameter(name = "mobile", description = "手机号", required = true)
-    })
-    public Result sendCode(@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
-        String mobile = params.get("mobile").toString();
+    public Result sendCode(
+            @Parameter(name = "mobile",description = "接收验证码的手机号码",required = true,schema = @Schema(type = "string", example = "13812345678")) @RequestParam String mobile
+    ) {
         //校验手机号是否为空或者格式是否正确
         if(StringUtils.isBlank(mobile) || mobile.length() != 11){
-            return new Result().error("手机号格式不正确");
+            return new Result().error(ErrorCode.PARAMS_GET_ERROR,"手机号格式不正确");
         }
         //查询手机号今天发送验证码次数
         Object timesObj = redisUtils.hGet(RedisKeys.getSmsCaptchaTimesKey(),mobile);
         if (timesObj != null && Integer.parseInt(timesObj.toString()) > 10) {
-            return new Result().error("24小时内发送验证码次数超过10次");
+            return new Result().error(ErrorCode.PARAMS_GET_ERROR,"24小时内发送验证码次数超过10次");
         }
         //查询手机号是否注册过
         UserEntity userEntity = userService.getByMobile(mobile);
         if (userEntity != null) {
-            return new Result().error("手机号已注册");
+            return new Result().error(ErrorCode.DB_RECORD_EXISTS,"手机号已注册");
         }
         //发送验证码
         String code = RandomUtil.randomNumbers(6);
@@ -90,7 +88,7 @@ public class ApiRegisterController {
         //校验验证码
         Object codeObj = redisUtils.hGet(RedisKeys.getSmsCaptchaKey(),dto.getMobile());
         if (codeObj == null || !codeObj.toString().equals(dto.getCode())) {
-            return new Result().error("验证码不正确");
+            return new Result().error(ErrorCode.CAPTCHA_ERROR,"验证码不正确");
         }
         //保存用户信息
         UserEntity user = new UserEntity();