Compare commits

..

No commits in common. "3b7303682fc95a91ae90acd2a38d542019fff2a0" and "d3471e56180e51bc929933e7f98ae25e70f80612" have entirely different histories.

2 changed files with 6 additions and 31 deletions

View File

@ -97,7 +97,6 @@ public enum ErrorCode {
SMS_SOURCE_CODE_NOT_EXIST("04-01-001", "短信码不存在"),
SMS_CODE_EXPIRED("04-01-002", "验证码过期,请重新发送"),
SMS_CODE_NOT_RIGHT("04-01-003", "验证码不正确"),
SMS_CODE_TOO_FREQUENT("04-01-004", "操作过于频繁,请稍后再试"),
// gbs
GBS_USER_ERROR("04-01-001", "gbs用户未登录"),

View File

@ -13,8 +13,6 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.qinan.safetyeval.client.dto.SendMessageCmd;
import org.qinan.safetyeval.domain.exception.BizException;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
@ -35,7 +33,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import static org.qinan.safetyeval.domain.exception.ErrorCode.*;
@ -62,7 +59,6 @@ public class SmsRemote {
@DubboReference
private MessageFacade messageFacade;
private final RedisService redisService;
private final RedissonClient redissonClient;
@Value("${sms.sign.sourceCode:}")
@ -101,34 +97,14 @@ public class SmsRemote {
}
public SingleResponse<String> signValidCode(String bizId, String validCode) {
// 以 bizId 为 key 加分布式锁,锁 1s防止刷验证码
RLock lock = redissonClient.getLock(bizId);
boolean locked;
try {
// 不等待,拿不到锁即视为频繁操作;锁自动 1s 后释放
locked = lock.tryLock(0, 1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new BizException(SMS_CODE_TOO_FREQUENT);
}
if (!locked) {
throw new BizException(SMS_CODE_TOO_FREQUENT);
}
try {
Object code = redisService.get(bizId);
if (code == null) {
throw new BizException(SMS_CODE_EXPIRED);
}
if (code.toString().equals(validCode)) {
throw new BizException(SMS_CODE_NOT_RIGHT);
}
return SingleResponse.of(bizId);
} finally {
if (lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
}
/**