添加手机短信登录验证码

This commit is contained in:
wanggeng888 2021-05-05 12:39:13 +08:00
parent d6ff85b7e7
commit 888b817df4

View File

@ -2,8 +2,10 @@ package ink.wgink.login.app.controller.app.api.appsign;
import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.exceptions.DependencyException;
import ink.wgink.exceptions.ParamsException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.interfaces.sms.ISmsBaseService;
import ink.wgink.login.app.pojo.vos.appsign.AppLoginDefaultVO;
import ink.wgink.login.app.pojo.vos.appsign.AppLoginPhoneVO;
import ink.wgink.login.app.service.appsign.IAppSignService;
@ -14,6 +16,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -39,6 +42,8 @@ public class AppSignAppController extends DefaultBaseController {
@Autowired
private IAppSignService appSignService;
@Autowired(required = false)
private ISmsBaseService smsBaseService;
@ApiOperation(value = "APP用户名密码登录", notes = "APP用户名密码登录接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@ -53,16 +58,19 @@ public class AppSignAppController extends DefaultBaseController {
@PostMapping("phone")
@CheckRequestBodyAnnotation
public synchronized SuccessResultData<String> phone(@RequestBody AppLoginPhoneVO appLoginPhoneVO) throws Exception {
if(smsBaseService == null) {
throw new DependencyException("短信依赖未引入");
}
if (!RegexUtil.isPhone(appLoginPhoneVO.getUsername())) {
throw new ParamsException("用户名非手机格式");
}
// String verificationCode = VerificationCodeManager.getInstance().getVerificationCode(appLoginPhoneVO.getUsername());
// if (StringUtils.isBlank(verificationCode)) {
// throw new ParamsException("验证码为空");
// }
// if (!StringUtils.equalsIgnoreCase(verificationCode, appLoginPhoneVO.getVerificationCode())) {
// throw new ParamsException("验证码错误");
// }
String verifyCode = smsBaseService.getVerifyCode(appLoginPhoneVO.getUsername());
if (StringUtils.isBlank(verifyCode)) {
throw new ParamsException("验证码为空");
}
if (!StringUtils.equalsIgnoreCase(verifyCode, appLoginPhoneVO.getVerificationCode())) {
throw new ParamsException("验证码错误");
}
return new SuccessResultData<>(appSignService.phoneSign(appLoginPhoneVO));
}