Commit a23071f7 by 韦华德

民政单点登录:增加手机验证码,注册去掉邮箱

parent 45e80ae8
......@@ -69,7 +69,8 @@ public class SsoController {
@ApiOperation("获取手机验证码")
@AnonymousGetMapping(value = "/getPhoneVerificationCode/{phoneNumber}")
public ResultVo getPhoneVerificationCode(@PathVariable("phoneNumber") String phoneNumber) {
return ResultVo.success(ssoService.getPhoneVerificationCode(phoneNumber));
ssoService.getPhoneVerificationCode(phoneNumber);
return ResultVo.success();
}
......
package com.zq.system.modules.system.service;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
......@@ -34,7 +35,7 @@ import com.zq.system.utils.MobileSmsUtils;
import com.zq.system.utils.RsaUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.core.Authentication;
......@@ -79,9 +80,7 @@ public class SsoService {
}
AssertUtils.hasText(passwd, "密码解密失败");
String phoneVerificationCode=redisUtils.getStr(vo.getUuId());
// AssertUtils.hasText(phoneVerificationCode,"验证码已过期");
// AssertUtils.isTrue(vo.getPhoneVerificationCode().equals(phoneVerificationCode),"验证码错误");
verificationCode(vo.getPhone(), vo.getPhoneVerificationCode());
User resources=new User();
resources.setPassword(passwordEncoder.encode(passwd));
......@@ -245,12 +244,23 @@ public class SsoService {
return data;
}
public String getPhoneVerificationCode(String phoneNumber) {
String code= String.valueOf((int)((Math.random()*9+1)*100000));
MobileSmsUtils.sendMsg(phoneNumber,"【民政统一登录平台】验证码:"+code+"(有效期为3分钟),请勿泄露给他人,如非本人操作,请忽略此信息。");
String uuid = properties.getCodeKey() + IdUtil.simpleUUID();
//3分钟
redisUtils.setStr(uuid,code,180000);
return uuid;
public void getPhoneVerificationCode(String phone) {
String code = RandomUtil.randomNumbers(6);
String content = "您的验证码为:" + code + "(5分钟内有效)。为了保障信息安全,如非本人操作请忽略本短信。";
boolean sendMsg = MobileSmsUtils.sendMsg(phone, content);
log.info(">> phone: {}, sendCode: {}, success: {}", phone, code, sendMsg);
redisUtils.setStr(CacheKeys.authCodeKey(phone), code, 5);
}
/**
* 判断验证码
*
* @param phone
* @param code
*/
public void verificationCode(String phone, String code) {
String cacheCode = redisUtils.getStr(CacheKeys.authCodeKey(phone));
AssertUtils.isTrue(StringUtils.isNotBlank(cacheCode) && cacheCode.equalsIgnoreCase(code), "验证码错误");
redisUtils.deleteStr(CacheKeys.authCodeKey(phone));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment