Commit f7456829 authored by 王亮's avatar 王亮

temp commit(SMS).

parent 9522d2e7
......@@ -249,7 +249,14 @@ public class SmsController implements IBaseController {
}
private JsonResult sendVerificationCode2Voice(String phoneNo, String randomCode, String usage) {
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSession();
String verificationCountKey = Constants.REDIS_VOICE_CODE_COUNT + phoneNo;
if (sessionStruct != null && !UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
verificationCountKey = Constants.REDIS_VOICE_CODE_COUNT + sessionStruct.getTenantId() + "_" +phoneNo;
}
Long getVerificationCount = redisTemplate.opsForHash().increment(verificationCountKey, usage, 1);
redisTemplate.expire(verificationCountKey, DateUtils.getSeconds(), TimeUnit.SECONDS);
if (getVerificationCount > PHONE_VOICE_MAX_PER_DAY) {
......@@ -259,7 +266,6 @@ public class SmsController implements IBaseController {
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
return JsonResult.buildErrorStateResult("手机号格式有误", null);
}
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSession();
String key = Constants.REDIS_PREFIX_VERIFICATION_CODE + phoneNo;
if (sessionStruct != null && !UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
......@@ -472,16 +478,30 @@ public class SmsController implements IBaseController {
if (StringUtils.isBlank(usage)) {
return JsonResult.buildErrorStateResult("usage参数无效", null);
}
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSession();
String clientIp = getIp();
log.info("请求短信新版本接口:phoneNo:{},deviceId:{},usage:{},IP:{}", phoneNo, deviceId, usage, clientIp);
// 手机号计数器
String verificationCountKey = Constants.REDIS_VOICE_CODE_COUNT + usage;
if (sessionStruct != null && !UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
verificationCountKey = Constants.REDIS_VOICE_CODE_COUNT + sessionStruct.getTenantId() + "_" +usage;
}
Long getPhoneVerificationCount = redisTemplate.opsForHash().increment(verificationCountKey, phoneNo, 1);
redisTemplate.expire(verificationCountKey, DateUtils.getSeconds(), TimeUnit.SECONDS);
// 设备号计数器
Long getDeviceVerificationCount = 0L;
if (StringUtils.isNotBlank(deviceId)) {
String verificationDeviceCountKey = Constants.REDIS_VOICE_DEVICE_COUNT + deviceId;
if (sessionStruct != null && !UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
verificationDeviceCountKey = Constants.REDIS_VOICE_DEVICE_COUNT + sessionStruct.getTenantId() + "_" +deviceId;
}
getDeviceVerificationCount = redisTemplate.opsForHash().increment(Constants.REDIS_VOICE_DEVICE_COUNT, verificationDeviceCountKey, 1);
redisTemplate.expire(Constants.REDIS_VOICE_DEVICE_COUNT, DateUtils.getSeconds(), TimeUnit.SECONDS);
}
......@@ -489,6 +509,10 @@ public class SmsController implements IBaseController {
Long getIPVerificationCount = 0L;
if (StringUtils.isNotBlank(clientIp)) {
String verificationIPCountKey = Constants.REDIS_VOICE_IP_COUNT + clientIp;
if (sessionStruct != null && !UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
verificationIPCountKey = Constants.REDIS_VOICE_IP_COUNT + sessionStruct.getTenantId() + "_" +clientIp;
}
getIPVerificationCount = redisTemplate.opsForHash().increment(Constants.REDIS_VOICE_IP_COUNT, verificationIPCountKey, 1);
redisTemplate.expire(Constants.REDIS_VOICE_IP_COUNT, DateUtils.getSeconds(), TimeUnit.SECONDS);
}
......@@ -508,7 +532,6 @@ public class SmsController implements IBaseController {
return JsonResult.buildErrorStateResult("您当前ip已经达到获取今天语音验证码上限", null);
}
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSession();
String key = Constants.REDIS_PREFIX_VERIFICATION_CODE + phoneNo;
if (sessionStruct != null && !UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
......@@ -565,7 +588,13 @@ public class SmsController implements IBaseController {
* @param phoneNo
*/
private void deleteRetSendCode(String phoneNo) {
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSession();
String verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + phoneNo;
if (sessionStruct != null && !UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + sessionStruct.getTenantId() + "_" +phoneNo;
}
redisTemplate.opsForHash().delete(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT);
}
......
......@@ -130,7 +130,11 @@ public class SmsServiceImpl implements ISmsService {
}
String uniqueId = arr[0];
String code = arr[1];
return confirmSms(smsVerifyReq.getCode(), uniqueId, code);
boolean result = confirmSms(smsVerifyReq.getCode(), uniqueId, code);
if(result){
deleteCodeFromCache(smsVerifyReq.getPhoneNo());
}
return result;
}
......@@ -155,8 +159,14 @@ public class SmsServiceImpl implements ISmsService {
@Override
public boolean needResendCode(String phoneNo, Long threshold, boolean isDelTryCount) {
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSession();
String verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + phoneNo;
if (sessionStruct != null && !UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + sessionStruct.getTenantId() + "_" +phoneNo;
}
Long getVerificationCount = stringRedisTemplate.opsForHash().increment(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT, 1);
boolean needResend = getVerificationCount >= threshold;
if (needResend) {
......@@ -171,7 +181,14 @@ public class SmsServiceImpl implements ISmsService {
@Override
public void deleteCodeFromCache(String phoneNo) {
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSession();
String verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + phoneNo;
if (sessionStruct != null && !UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + sessionStruct.getTenantId() + "_" +phoneNo;
}
stringRedisTemplate.opsForHash().delete(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT);
deleteOnlyCodeFromCache(phoneNo);
......
......@@ -160,7 +160,13 @@ public class SMSVerificationCodeStrategy implements VerificationCodeStrategy {
* @param phoneNo 手机号码
*/
private void deleteRetSendCode(String phoneNo) {
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSession();
String verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + phoneNo;
if (sessionStruct != null && !UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + sessionStruct.getTenantId() + "_" +phoneNo;
}
redisTemplate.opsForHash().delete(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT);
}
......
......@@ -99,12 +99,22 @@ public class SMSVoiceVerificationCodeStrategy implements VerificationCodeStrateg
String clientIp = sessionStruct.getIp();
// 手机号计数器
String verificationCountKey = Constants.REDIS_VOICE_CODE_COUNT + usage;
if (!UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
verificationCountKey = Constants.REDIS_VOICE_CODE_COUNT + sessionStruct.getTenantId() + "_" +usage;
}
Long getPhoneVerificationCount = redisTemplate.opsForHash().increment(verificationCountKey, phoneNo, 1);
redisTemplate.expire(verificationCountKey, DateUtils.getSeconds(), TimeUnit.SECONDS);
// 设备号计数器
Long getDeviceVerificationCount = 0L;
if (StringUtils.isNotBlank(sessionStruct.getScDeviceId())) {
String verificationDeviceCountKey = Constants.REDIS_VOICE_DEVICE_COUNT + sessionStruct.getScDeviceId();
if (!UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
verificationDeviceCountKey = Constants.REDIS_VOICE_DEVICE_COUNT + sessionStruct.getTenantId() + "_" +sessionStruct.getScDeviceId();
}
getDeviceVerificationCount = redisTemplate.opsForHash().increment(Constants.REDIS_VOICE_DEVICE_COUNT, verificationDeviceCountKey, 1);
redisTemplate.expire(Constants.REDIS_VOICE_DEVICE_COUNT, DateUtils.getSeconds(), TimeUnit.SECONDS);
}
......@@ -157,7 +167,14 @@ public class SMSVoiceVerificationCodeStrategy implements VerificationCodeStrateg
* @param phoneNo 手机号码
*/
private void deleteRetSendCode(String phoneNo) {
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSession();
String verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + phoneNo;
if (sessionStruct != null && !UserConstant.defaultTenantId.equals(sessionStruct.getTenantId())) {
verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + sessionStruct.getTenantId() + "_" +phoneNo;
}
redisTemplate.opsForHash().delete(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT);
}
......
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