| | |
| | | import cn.hutool.captcha.generator.CodeGenerator; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import jakarta.validation.constraints.NotBlank; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.dromara.common.core.constant.Constants; |
| | | import org.dromara.common.core.constant.GlobalConstants; |
| | | import org.dromara.common.core.domain.R; |
| | |
| | | import org.dromara.common.core.utils.reflect.ReflectUtils; |
| | | import org.dromara.common.mail.config.properties.MailProperties; |
| | | import org.dromara.common.mail.utils.MailUtils; |
| | | import org.dromara.common.ratelimiter.annotation.RateLimiter; |
| | | import org.dromara.common.ratelimiter.enums.LimitType; |
| | | import org.dromara.common.redis.utils.RedisUtils; |
| | | import org.dromara.common.web.config.properties.CaptchaProperties; |
| | | import org.dromara.common.web.enums.CaptchaType; |
| | | import org.dromara.sms4j.api.SmsBlend; |
| | | import org.dromara.sms4j.api.entity.SmsResponse; |
| | | import org.dromara.sms4j.core.factory.SmsFactory; |
| | | import org.dromara.sms4j.provider.enumerate.SupplierType; |
| | | import org.dromara.web.domain.vo.CaptchaVo; |
| | | import jakarta.validation.constraints.NotBlank; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.expression.Expression; |
| | | import org.springframework.expression.ExpressionParser; |
| | | import org.springframework.expression.spel.standard.SpelExpressionParser; |
| | |
| | | * |
| | | * @param phonenumber 用户手机号 |
| | | */ |
| | | @RateLimiter(key = "#phonenumber", time = 60, count = 1) |
| | | @GetMapping("/resource/sms/code") |
| | | public R<Void> smsCode(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) { |
| | | String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber; |
| | |
| | | String templateId = ""; |
| | | LinkedHashMap<String, String> map = new LinkedHashMap<>(1); |
| | | map.put("code", code); |
| | | SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA); |
| | | SmsBlend smsBlend = SmsFactory.getSmsBlend("config1"); |
| | | SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map); |
| | | if (!"OK".equals(smsResponse.getCode())) { |
| | | if (!smsResponse.isSuccess()) { |
| | | log.error("验证码短信发送异常 => {}", smsResponse); |
| | | return R.fail(smsResponse.getMessage()); |
| | | return R.fail(smsResponse.getData().toString()); |
| | | } |
| | | return R.ok(); |
| | | } |
| | |
| | | * |
| | | * @param email 邮箱 |
| | | */ |
| | | @RateLimiter(key = "#email", time = 60, count = 1) |
| | | @GetMapping("/resource/email/code") |
| | | public R<Void> emailCode(@NotBlank(message = "{user.email.not.blank}") String email) { |
| | | if (!mailProperties.getEnabled()) { |
| | |
| | | /** |
| | | * 生成验证码 |
| | | */ |
| | | @GetMapping("/code") |
| | | @RateLimiter(time = 60, count = 10, limitType = LimitType.IP) |
| | | @GetMapping("/auth/code") |
| | | public R<CaptchaVo> getCode() { |
| | | CaptchaVo captchaVo = new CaptchaVo(); |
| | | boolean captchaEnabled = captchaProperties.getEnable(); |