|
@@ -1,12 +1,24 @@
|
|
|
package boot.modules.common.controller;
|
|
|
|
|
|
+import boot.common.constant.SchoolConstant;
|
|
|
+import boot.common.enums.SmsTypeEnum;
|
|
|
+import boot.common.respond.ApiCode;
|
|
|
import boot.common.respond.ApiResult;
|
|
|
+import boot.common.utils.RedisUtils;
|
|
|
import boot.common.utils.UploadUtils;
|
|
|
+import boot.modules.user.param.VerityParam;
|
|
|
+import boot.modules.user.pojo.User;
|
|
|
+import boot.modules.user.service.UserService;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -18,6 +30,8 @@ import java.util.List;
|
|
|
@RestController
|
|
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
public class CommonController {
|
|
|
+ private final UserService userService;
|
|
|
+ private final RedisUtils redisUtil;
|
|
|
/**
|
|
|
* 图片上传
|
|
|
*/
|
|
@@ -32,4 +46,44 @@ public class CommonController {
|
|
|
//返回访问的文件路径
|
|
|
return ApiResult.ok(url);
|
|
|
}
|
|
|
+
|
|
|
+ @PostMapping("/register/verify")
|
|
|
+ @ApiOperation(value = "短信验证码发送", notes = "短信验证码发送")
|
|
|
+ public ApiResult<String> verify(@Validated @RequestBody VerityParam param) {
|
|
|
+ User shopUser = userService.getOne(Wrappers.<User>lambdaQuery()
|
|
|
+ .eq(User::getPhone, param.getPhone()), false);
|
|
|
+ if (SmsTypeEnum.REGISTER.getValue().equals(param.getType()) && ObjectUtil.isNotNull(shopUser)) {
|
|
|
+ return ApiResult.fail(ApiCode.FAIL,"手机号已注册");
|
|
|
+ }
|
|
|
+ if (SmsTypeEnum.LOGIN.getValue().equals(param.getType()) && ObjectUtil.isNull(shopUser)) {
|
|
|
+ return ApiResult.fail(ApiCode.FAIL,"账号不存在");
|
|
|
+ }
|
|
|
+ String codeKey = "code_" + param.getPhone();
|
|
|
+ if (ObjectUtil.isNotNull(redisUtil.get(codeKey))) {
|
|
|
+ return ApiResult.fail(ApiCode.FAIL,"10分钟内有效:" + redisUtil.get(codeKey).toString());
|
|
|
+ }
|
|
|
+ String code = RandomUtil.randomNumbers(SchoolConstant.SCHOOL_SMS_SIZE);
|
|
|
+
|
|
|
+ //redis存储
|
|
|
+ redisUtil.set(codeKey, code, SchoolConstant.SCHOOL_SMS_REDIS_TIME);
|
|
|
+
|
|
|
+// String enable = redisUtil.getY("sms_enable");
|
|
|
+ Boolean enable = false;
|
|
|
+// if (SchoolEnum.ENABLE_2.getValue().toString().equals(enable)) {
|
|
|
+ return ApiResult.ok(code);
|
|
|
+// }
|
|
|
+
|
|
|
+ //发送阿里云短信
|
|
|
+// JSONObject json = new JSONObject();
|
|
|
+// json.put("code", code);
|
|
|
+// try {
|
|
|
+// SmsUtils.sendSms(param.getPhone(), json.toJSONString());
|
|
|
+// } catch (ClientException e) {
|
|
|
+// redisUtil.del(codeKey);
|
|
|
+// e.printStackTrace();
|
|
|
+// return ApiResult.ok("发送失败:" + e.getErrMsg());
|
|
|
+// }
|
|
|
+// return ApiResult.ok("发送成功,请注意查收");
|
|
|
+
|
|
|
+ }
|
|
|
}
|