|
@@ -1,23 +1,19 @@
|
|
|
package com.ym.mec.common.validcode.impl;
|
|
|
|
|
|
-import com.ym.mec.thirdparty.message.MessageSenderPlugin;
|
|
|
-import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.ym.mec.common.redis.service.RedisCache;
|
|
|
import com.ym.mec.common.validcode.SmsCodeService;
|
|
|
+import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
|
|
|
@Service
|
|
|
public class SmsCodeServiceImpl implements SmsCodeService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private RedisTemplate<String,String> redisTemplate;
|
|
|
|
|
|
- private RedisCache<String,String> redisCache = new RedisCache<String, String>(redisTemplate);
|
|
|
+ @Autowired
|
|
|
+ private RedisCache<String,Object> redisCache;
|
|
|
|
|
|
private final String loginVerifyCodeKey = "loginVerifyCode:";
|
|
|
|
|
@@ -28,7 +24,7 @@ public class SmsCodeServiceImpl implements SmsCodeService {
|
|
|
|
|
|
@Override
|
|
|
public boolean verifyValidCode(String mobile, String authCode) {
|
|
|
- String verifyCode = redisTemplate.opsForValue().get(loginVerifyCodeKey + mobile);
|
|
|
+ String verifyCode = (String) redisCache.get(loginVerifyCodeKey + mobile);
|
|
|
if(StringUtils.isNoneEmpty(verifyCode) && StringUtils.equalsIgnoreCase(verifyCode,authCode)){
|
|
|
return true;
|
|
|
}
|
|
@@ -40,19 +36,19 @@ public class SmsCodeServiceImpl implements SmsCodeService {
|
|
|
String code = RandomStringUtils.randomNumeric(6);
|
|
|
// 发送验证码
|
|
|
// messageSenderPluginContext.send(MessageSenderPluginContext.MessageSender.YIMEI,"","",mobile,"");
|
|
|
- redisTemplate.opsForValue().set(loginVerifyCodeKey + mobile, code, expireTime);
|
|
|
+ redisCache.put(loginVerifyCodeKey + mobile, code, expireTime);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getValidCode(String mobile) {
|
|
|
- return redisTemplate.opsForValue().get(loginVerifyCodeKey + mobile);
|
|
|
+ return (String) redisCache.get(loginVerifyCodeKey + mobile);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void removeValidCode(String mobile) {
|
|
|
- if (redisTemplate.hasKey(loginVerifyCodeKey + mobile)) {
|
|
|
- redisTemplate.delete(loginVerifyCodeKey + mobile);
|
|
|
+ if (redisCache.exists(loginVerifyCodeKey + mobile)) {
|
|
|
+ redisCache.delete(loginVerifyCodeKey + mobile);
|
|
|
}
|
|
|
}
|
|
|
|