package com.philisense.www.api.generator.impl;

import com.philisense.www.api.generator.VcodeGenerator;
import com.philisense.www.dto.SmsCode;
import com.philisense.www.properties.VcodeProperties;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.web.context.request.ServletWebRequest;

import javax.annotation.Resource;

/**
 * 短信验证码生成
 */
public class SmsCodeGenerator implements VcodeGenerator {

    @Resource
    private VcodeProperties vcodeProperties;

    @Override
    public SmsCode generate(ServletWebRequest request) {
        int length = vcodeProperties.getCodeLength();
        String code = RandomStringUtils.randomNumeric(length);
        return new SmsCode(code);
    }
}
