diff --git a/pom.xml b/pom.xml
index e764a5a..a5445b3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -191,6 +191,11 @@
commons-compress
1.19
+
+ com.tencentcloudapi
+ tencentcloud-sdk-java
+ 3.1.501
+
diff --git a/src/main/java/cn/com/tenlion/operator/controller/api/verify/code/VerifyCodeController.java b/src/main/java/cn/com/tenlion/operator/controller/api/verify/code/VerifyCodeController.java
new file mode 100644
index 0000000..4c8885a
--- /dev/null
+++ b/src/main/java/cn/com/tenlion/operator/controller/api/verify/code/VerifyCodeController.java
@@ -0,0 +1,39 @@
+package cn.com.tenlion.operator.controller.api.verify.code;
+
+import cn.com.tenlion.operator.service.verify.code.VerifyCodeService;
+import ink.wgink.common.base.DefaultBaseController;
+import ink.wgink.exceptions.ParamsException;
+import ink.wgink.interfaces.consts.ISystemConstant;
+import ink.wgink.pojo.result.ErrorResult;
+import ink.wgink.pojo.result.SuccessResult;
+import ink.wgink.util.RegexUtil;
+import io.swagger.annotations.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "验证码接口")
+@RestController
+@RequestMapping(ISystemConstant.API_PREFIX + "/verify/code")
+public class VerifyCodeController extends DefaultBaseController {
+
+ @Autowired
+ private VerifyCodeService verifyCodeService;
+
+ @ApiOperation(value = "获取短信验证码", notes = "获取短信验证码接口")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "phone", value = "手机", paramType = "path"),
+ })
+ @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
+ @GetMapping("send/{phone}")
+ public SuccessResult send(@PathVariable("phone") String phone) {
+ if (!RegexUtil.isPhone(phone)) {
+ throw new ParamsException("手机号格式错误");
+ }
+ verifyCodeService.send(phone);
+ return new SuccessResult();
+ }
+
+}
diff --git a/src/main/java/cn/com/tenlion/operator/login/phone/auth/LoginPhoneAuthFilter.java b/src/main/java/cn/com/tenlion/operator/login/phone/auth/LoginPhoneAuthFilter.java
index c50628a..7823b48 100644
--- a/src/main/java/cn/com/tenlion/operator/login/phone/auth/LoginPhoneAuthFilter.java
+++ b/src/main/java/cn/com/tenlion/operator/login/phone/auth/LoginPhoneAuthFilter.java
@@ -1,5 +1,6 @@
package cn.com.tenlion.operator.login.phone.auth;
+import ink.wgink.exceptions.ParamsException;
import ink.wgink.login.base.exceptions.UserAuthenticationException;
import ink.wgink.module.sms.service.sms.ISmsService;
import ink.wgink.service.user.enums.UserStateEnum;
@@ -31,19 +32,17 @@ public class LoginPhoneAuthFilter extends AbstractAuthenticationProcessingFilter
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
String phone = request.getParameter("username").trim();
- String code = request.getParameter("code").trim();
+ String smsCode = request.getParameter("smsCode").trim();
if (StringUtils.isBlank(phone)) {
throw new UserAuthenticationException("手机号不能为空");
}
- if (StringUtils.isBlank(code)) {
+ if (StringUtils.isBlank(smsCode)) {
throw new UserAuthenticationException("验证码不能为空");
}
- String verifyCode = smsService.getVerifyCode(phone);
- if (StringUtils.isBlank(verifyCode)) {
- throw new UserAuthenticationException("验证码错误");
- }
- if (!StringUtils.equals(code, verifyCode)) {
- throw new UserAuthenticationException("验证码不匹配");
+ try {
+ smsService.checkVerifyCode(phone, smsCode);
+ } catch (ParamsException e) {
+ throw new UserAuthenticationException(e.getMessage());
}
/**
* 查到用户
diff --git a/src/main/java/cn/com/tenlion/operator/service/verify/code/VerifyCodeService.java b/src/main/java/cn/com/tenlion/operator/service/verify/code/VerifyCodeService.java
new file mode 100644
index 0000000..62975a4
--- /dev/null
+++ b/src/main/java/cn/com/tenlion/operator/service/verify/code/VerifyCodeService.java
@@ -0,0 +1,57 @@
+package cn.com.tenlion.operator.service.verify.code;
+
+import ink.wgink.common.base.DefaultBaseService;
+import ink.wgink.exceptions.ParamsException;
+import ink.wgink.exceptions.base.SystemException;
+import ink.wgink.module.sms.factory.sms.ISmsSend;
+import ink.wgink.module.sms.factory.sms.SmsSendFactory;
+import ink.wgink.module.sms.factory.sms.impl.TencentSmsSendImpl;
+import ink.wgink.module.sms.manager.VerifyCodeManager;
+import ink.wgink.module.sms.pojo.vos.sms.SmsVO;
+import ink.wgink.module.sms.service.sms.ISmsService;
+import ink.wgink.properties.sms.SmsProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class VerifyCodeService extends DefaultBaseService {
+
+ @Autowired
+ private SmsProperties smsProperties;
+ @Autowired
+ private ISmsService smsService;
+
+
+ public void send(String phone) {
+ VerifyCodeManager verifyCodeManager = VerifyCodeManager.getInstance();
+ long timeRemaining = verifyCodeManager.effectiveVerificationCodeTimeRemaining(phone);
+ if (timeRemaining > 0) {
+ throw new ParamsException(String.format("验证码已发送,若没有收到,请在%d秒后重试", (timeRemaining / 1000)));
+ }
+
+ String currentTimeStr = String.valueOf(System.currentTimeMillis());
+ String code = currentTimeStr.substring(currentTimeStr.length() - 6);
+ LOG.info(">>>>> 向手机号:{},发送验证码:{}", phone, code);
+
+
+ SmsVO smsVO = new SmsVO();
+ smsVO.setPhone(phone);
+ smsVO.setContent(code);
+ try {
+ if (smsProperties.getActive()) {
+ ISmsSend smsSend = new TencentSmsSendImpl(smsProperties.getTencentSms());
+ smsSend.code(phone, code);
+ }
+ verifyCodeManager.setVerificationCode(phone, code);
+ smsVO.setSendStatus(1);
+ } catch (Exception e) {
+ LOG.error(e.getMessage());
+ String errorMessage = e.getMessage();
+ smsVO.setSendStatus(0);
+ smsVO.setErrorMessage(errorMessage);
+ throw new SystemException("短信发送失败");
+ } finally {
+ smsService.save(smsVO);
+ }
+ }
+}
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
index fd1501d..a48723f 100644
--- a/src/main/resources/application-dev.yml
+++ b/src/main/resources/application-dev.yml
@@ -139,14 +139,20 @@ api-path:
#
# 短信验证码服务
sms:
- active: true
+ active: false
type: default
default-sms:
account: xd001382
password: xd001382136
- sign: 【AI秒著引擎】
+ sign: 【AI秒著网】
template:
verification-code: '{sign} 您的验证码为 {content}, 有效时间为120秒,若非本人操作,请忽略。'
+ tencent-sms:
+ secret-id: AKID1wfBXhr287weLsFTm05zlYHsNn3871sY
+ secret-key: d4PaebVKzWs8IKG7uY2SmyxpeMtHYihX
+ sdk-app-id: 1400945659
+ sign-name: AI秒著网
+ verification-code-template-id: 2295389
pay:
wx-pay:
diff --git a/src/main/resources/templates/systemuser/login-old.html b/src/main/resources/templates/systemuser/login-old.html
new file mode 100644
index 0000000..fdec520
--- /dev/null
+++ b/src/main/resources/templates/systemuser/login-old.html
@@ -0,0 +1,798 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
修改密码
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/templates/systemuser/login.html b/src/main/resources/templates/systemuser/login.html
index bbaf258..03fbea7 100644
--- a/src/main/resources/templates/systemuser/login.html
+++ b/src/main/resources/templates/systemuser/login.html
@@ -2,7 +2,7 @@
-
+
@@ -14,446 +14,120 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
修改密码
-
-
-
-
+