Commit 0da9796c authored by 施翔轲's avatar 施翔轲

新增临时发送短信、校验短信接口,用于删除组织时提供校验

parent fc0b6d73
...@@ -10,6 +10,9 @@ import com.dsk.common.constant.Constants; ...@@ -10,6 +10,9 @@ import com.dsk.common.constant.Constants;
import com.dsk.common.constant.GlobalConstants; import com.dsk.common.constant.GlobalConstants;
import com.dsk.common.core.domain.R; import com.dsk.common.core.domain.R;
import com.dsk.common.enums.CaptchaType; import com.dsk.common.enums.CaptchaType;
import com.dsk.common.exception.user.CaptchaExpireException;
import com.dsk.common.helper.LoginHelper;
import com.dsk.common.utils.MessageUtils;
import com.dsk.common.utils.StringUtils; import com.dsk.common.utils.StringUtils;
import com.dsk.common.utils.email.MailUtils; import com.dsk.common.utils.email.MailUtils;
import com.dsk.common.utils.redis.RedisUtils; import com.dsk.common.utils.redis.RedisUtils;
...@@ -17,6 +20,8 @@ import com.dsk.common.utils.reflect.ReflectUtils; ...@@ -17,6 +20,8 @@ import com.dsk.common.utils.reflect.ReflectUtils;
import com.dsk.common.utils.spring.SpringUtils; import com.dsk.common.utils.spring.SpringUtils;
import com.dsk.framework.config.properties.CaptchaProperties; import com.dsk.framework.config.properties.CaptchaProperties;
import com.dsk.framework.config.properties.MailProperties; import com.dsk.framework.config.properties.MailProperties;
import com.dsk.system.domain.SysUser;
import com.dsk.system.mapper.SysUserMapper;
import com.dsk.system.service.ISysConfigService; import com.dsk.system.service.ISysConfigService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -29,6 +34,7 @@ import org.springframework.expression.ExpressionParser; ...@@ -29,6 +34,7 @@ import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
...@@ -52,16 +58,17 @@ public class CaptchaController { ...@@ -52,16 +58,17 @@ public class CaptchaController {
private final CaptchaProperties captchaProperties; private final CaptchaProperties captchaProperties;
private final ISysConfigService configService; private final ISysConfigService configService;
private final MailProperties mailProperties; private final MailProperties mailProperties;
private final SysUserMapper userMapper;
/** /**
* 短信验证码 * 发送短信验证码
* *
* @param phonenumber 用户手机号 * @param phonenumber 用户手机号
*/ */
@GetMapping("/captchaSms") @GetMapping("/captchaSms")
public R<Void> smsCaptcha(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) { public R<Void> smsCaptcha(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) {
String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber; String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber;
String code = RandomUtil.randomNumbers(4); String code = RandomUtil.randomNumbers(6);
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION)); RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
// 验证码模板id 自行处理 (查数据库或写死均可) // 验证码模板id 自行处理 (查数据库或写死均可)
String templateId = ""; String templateId = "";
...@@ -77,7 +84,39 @@ public class CaptchaController { ...@@ -77,7 +84,39 @@ public class CaptchaController {
} }
/** /**
* 邮箱验证码 * 开发需要,临时发送短信验证码
*/
@GetMapping("/getTempSmsCode")
public R<Void> getTempSmsCode() {
SysUser sysUser = userMapper.selectUserById(LoginHelper.getUserId());
String key = GlobalConstants.CAPTCHA_CODE_KEY + sysUser.getPhonenumber();
String code = RandomUtil.randomNumbers(6);
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
return R.ok("验证码:" + code);
}
/**
* 开发需要,临时校验短信验证码
*
* @param smsCode 验证码
*/
@PostMapping("/checkSmsCode")
public R<Boolean> checkSmsCode(String smsCode) {
SysUser sysUser = userMapper.selectUserById(LoginHelper.getUserId());
String key = GlobalConstants.CAPTCHA_CODE_KEY + sysUser.getPhonenumber();
String code = RedisUtils.getCacheObject(key);
if (StringUtils.isBlank(code)) {
throw new CaptchaExpireException();
}
if (code.equals(smsCode)) {
RedisUtils.deleteObject(key);
return R.ok("校验成功");
}
return R.fail("验证码错误");
}
/**
* 发送邮箱验证码
* *
* @param email 邮箱 * @param email 邮箱
*/ */
...@@ -126,7 +165,7 @@ public class CaptchaController { ...@@ -126,7 +165,7 @@ public class CaptchaController {
Expression exp = parser.parseExpression(StringUtils.remove(code, "=")); Expression exp = parser.parseExpression(StringUtils.remove(code, "="));
code = exp.getValue(String.class); code = exp.getValue(String.class);
} }
log.info("图形验证码:"+code); log.info("图形验证码:" + code);
RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION)); RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
ajax.put("uuid", uuid); ajax.put("uuid", uuid);
ajax.put("img", captcha.getImageBase64()); ajax.put("img", captcha.getImageBase64());
......
...@@ -65,7 +65,7 @@ public interface Constants { ...@@ -65,7 +65,7 @@ public interface Constants {
/** /**
* 验证码有效期(分钟) * 验证码有效期(分钟)
*/ */
Integer CAPTCHA_EXPIRATION = 2; Integer CAPTCHA_EXPIRATION = 5;
/** /**
* 令牌 * 令牌
......
...@@ -21,7 +21,7 @@ public class DingTalkUtil { ...@@ -21,7 +21,7 @@ public class DingTalkUtil {
* 钉钉机器人发消息地址(配置机器人的webhook) * 钉钉机器人发消息地址(配置机器人的webhook)
* 此处大家可以配置到配置文件等等方式 * 此处大家可以配置到配置文件等等方式
*/ */
private static final String MSG_URL = "https://oapi.dingtalk.com/robot/send?access_token=d348d1f6ee759e03e6ee214622164c9bda653565a62e92b8685577e8796bcdfb"; private static final String MSG_URL = "https://oapi.dingtalk.com/robot/send?access_token=ab6a16dacc0f7e8051bf5b34d425382ffa22621cf3876d81a5331ab30a1bbb14";
/** /**
* 通知具体人 * 通知具体人
......
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