com.healthy.common.security.code.sms.SmsCodeGenerator Maven / Gradle / Ivy
package com.healthy.common.security.code.sms;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.healthy.common.security.code.ValidateCode;
import com.healthy.common.security.code.ValidateCodeGenerator;
import com.healthy.common.security.properties.SmsCodeProperties;
import org.springframework.web.context.request.ServletWebRequest;
/**
* SmsCodeGenerator
*
* @author xiaomingzhang
*/
public class SmsCodeGenerator implements ValidateCodeGenerator {
private SmsCodeProperties smsCodeProperties;
@Override
public ValidateCode generate(ServletWebRequest request) {
String code = StrUtil.blankToDefault(smsCodeProperties.getTestCode(), RandomUtil.randomNumbers(smsCodeProperties.getLength()));
return new ValidateCode(code, smsCodeProperties.getExpireIn());
}
public void setSmsCodeProperties(SmsCodeProperties smsCodeProperties) {
this.smsCodeProperties = smsCodeProperties;
}
}