cn.herodotus.engine.access.sms.stamp.VerificationCodeStampManager Maven / Gradle / Ivy
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2020-2030 郑庚伟 ZHENGGENGWEI (码匠君), Licensed under the AGPL License
*
* This file is part of Herodotus Engine.
*
* Herodotus Engine is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Herodotus Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package cn.herodotus.engine.access.sms.stamp;
import cn.herodotus.engine.access.core.constants.AccessConstants;
import cn.herodotus.engine.access.sms.properties.SmsProperties;
import cn.herodotus.engine.cache.jetcache.stamp.AbstractStampManager;
import org.dromara.hutool.core.util.RandomUtil;
/**
* Description: 手机短信验证码签章
*
* @author : gengwei.zheng
* @date : 2021/8/26 17:44
*/
public class VerificationCodeStampManager extends AbstractStampManager {
private SmsProperties smsProperties;
public VerificationCodeStampManager() {
super(AccessConstants.CACHE_NAME_TOKEN_VERIFICATION_CODE);
}
public void setSmsProperties(SmsProperties smsProperties) {
this.smsProperties = smsProperties;
}
@Override
public String nextStamp(String key) {
if (smsProperties.getSandbox()) {
return smsProperties.getTestCode();
} else {
return RandomUtil.randomNumbers(smsProperties.getLength());
}
}
@Override
public void afterPropertiesSet() throws Exception {
super.setExpire(smsProperties.getExpire());
}
public Boolean getSandbox() {
return smsProperties.getSandbox();
}
public String getVerificationCodeTemplateId() {
return smsProperties.getVerificationCodeTemplateId();
}
}