You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.3 KiB
35 lines
1.3 KiB
package com.mydreamjob.auth.sms;
|
|
|
|
import lombok.Getter;
|
|
import lombok.Setter;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
/** 不生成 toString,避免配置对象输出凭据。只有显式 true 才启用。 */
|
|
@Getter
|
|
@Setter
|
|
@ConfigurationProperties(prefix = "app.sms.aliyun")
|
|
public class AliyunSmsProperties {
|
|
private String enabled = "false";
|
|
private String accessKeyId;
|
|
private String accessKeySecret;
|
|
private String signName;
|
|
private String templateCode;
|
|
private int connectTimeoutMs = 3000;
|
|
private int readTimeoutMs = 5000;
|
|
|
|
public boolean explicitlyEnabled() {
|
|
return enabled != null && "true".equalsIgnoreCase(enabled.trim());
|
|
}
|
|
|
|
public void validateForSending() {
|
|
if (blank(accessKeyId) || blank(accessKeySecret) || blank(signName) || blank(templateCode)
|
|
|| !templateCode.matches("SMS_[A-Za-z0-9_]+")
|
|
|| connectTimeoutMs < 1000 || connectTimeoutMs > 30000
|
|
|| readTimeoutMs < 1000 || readTimeoutMs > 30000) {
|
|
// 不使用包含 rejected value 的校验异常,避免绑定密钥进入启动日志。
|
|
throw new IllegalStateException("SMS configuration incomplete or invalid");
|
|
}
|
|
}
|
|
|
|
private static boolean blank(String value) { return value == null || value.isBlank(); }
|
|
}
|
|
|