All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.healthy.common.security.code.sms.SmsCodeGenerator Maven / Gradle / Ivy

There is a newer version: 1.2.1.RELEASE
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy