package com.yeshi.location.app.service.manager;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.stereotype.Component;
|
import org.yeshi.utils.NumberUtil;
|
import org.yeshi.utils.StringUtil;
|
import org.yeshi.utils.sms.TencentSMSUtil;
|
import org.yeshi.utils.sms.VerifyCodeFactory;
|
|
import javax.annotation.Resource;
|
import java.util.concurrent.TimeUnit;
|
|
/**
|
* @author hxh
|
* @title: VerifyCodeManager
|
* @description: 验证码管理
|
* @date 2021/11/15 18:38
|
*/
|
@Component
|
public class VerifyCodeManager {
|
@Resource
|
private RedisTemplate<String, String> redisTemplate;
|
|
/**
|
* @return void
|
* @author hxh
|
* @description 发送电话验证码
|
* @date 18:40 2021/11/15
|
* @param: phone
|
* @param: msg 变量为:{验证码}
|
**/
|
public void sendSMSSuccess(String phone, String code) {
|
|
redisTemplate.opsForValue().set("v-c-p-" + phone, code, 120, TimeUnit.SECONDS);
|
|
}
|
|
/**
|
* @return void
|
* @author hxh
|
* @description 发送邮箱验证码
|
* @date 18:41 2021/11/15
|
* @param: email
|
* @param: title
|
* @param: content
|
**/
|
public void sendEmailCodeSuccess(String email, String code) {
|
redisTemplate.opsForValue().set("v-c-e-" + StringUtil.Md5(email), code, 120, TimeUnit.SECONDS);
|
}
|
|
|
/**
|
* @return boolean
|
* @author hxh
|
* @description 电话验证码是否正确
|
* @date 19:05 2021/11/15
|
* @param: phone
|
* @param: code
|
**/
|
public boolean isPhoneCodeRight(String phone, String code) {
|
String oldCode = redisTemplate.opsForValue().get("v-c-p-" + phone);
|
return oldCode != null && oldCode.equalsIgnoreCase(code);
|
}
|
|
/**
|
* @return boolean
|
* @author hxh
|
* @description /邮箱验证码是否正确
|
* @date 19:05 2021/11/15
|
* @param: email
|
* @param: code
|
**/
|
public boolean isEMailCodeRight(String email, String code) {
|
String oldCode = redisTemplate.opsForValue().get("v-c-e-" + StringUtil.Md5(email));
|
return oldCode != null && oldCode.equalsIgnoreCase(code);
|
}
|
|
|
}
|