|
3 | 3 | import cn.hutool.core.lang.Assert; |
4 | 4 | import cn.hutool.core.map.MapUtil; |
5 | 5 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 6 | +import cn.iocoder.yudao.framework.common.util.date.DateUtils; |
6 | 7 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeCheckReqDTO; |
7 | 8 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; |
8 | 9 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; |
@@ -52,21 +53,22 @@ private String createSmsCode(String mobile, Integer scene, String ip) { |
52 | 53 | // 校验是否可以发送验证码,不用筛选场景 |
53 | 54 | SmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, null,null); |
54 | 55 | if (lastSmsCode != null) { |
55 | | - if (lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。 |
56 | | - throw ServiceExceptionUtil.exception(SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY); |
57 | | - } |
58 | 56 | if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime() |
59 | 57 | < smsCodeProperties.getSendFrequency().toMillis()) { // 发送过于频繁 |
60 | 58 | throw ServiceExceptionUtil.exception(SMS_CODE_SEND_TOO_FAST); |
61 | 59 | } |
| 60 | + if (DateUtils.isToday(lastSmsCode.getCreateTime()) && // 必须是今天,才能计算超过当天的上限 |
| 61 | + lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。 |
| 62 | + throw ServiceExceptionUtil.exception(SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY); |
| 63 | + } |
62 | 64 | // TODO 芋艿:提升,每个 IP 每天可发送数量 |
63 | 65 | // TODO 芋艿:提升,每个 IP 每小时可发送数量 |
64 | 66 | } |
65 | 67 |
|
66 | 68 | // 创建验证码记录 |
67 | 69 | String code = String.valueOf(randomInt(smsCodeProperties.getBeginCode(), smsCodeProperties.getEndCode() + 1)); |
68 | | - SmsCodeDO newSmsCode = SmsCodeDO.builder().mobile(mobile).code(code) |
69 | | - .scene(scene).todayIndex(lastSmsCode != null ? lastSmsCode.getTodayIndex() + 1 : 1) |
| 70 | + SmsCodeDO newSmsCode = SmsCodeDO.builder().mobile(mobile).code(code).scene(scene) |
| 71 | + .todayIndex(lastSmsCode != null && DateUtils.isToday(lastSmsCode.getCreateTime()) ? lastSmsCode.getTodayIndex() + 1 : 1) |
70 | 72 | .createIp(ip).used(false).build(); |
71 | 73 | smsCodeMapper.insert(newSmsCode); |
72 | 74 | return code; |
|
0 commit comments