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

org.macrocloud.kernel.sms.config.AliSmsConfiguration Maven / Gradle / Ivy

package org.macrocloud.kernel.sms.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import lombok.AllArgsConstructor;

import org.macrocloud.kernel.redis.cache.BaseRedis;
import org.macrocloud.kernel.sms.AliSmsTemplate;
import org.macrocloud.kernel.sms.props.SmsProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 阿里云短信配置类
 *
 */
@Configuration(proxyBeanMethods = false)
@AllArgsConstructor
@ConditionalOnClass(IAcsClient.class)
@EnableConfigurationProperties(SmsProperties.class)
@ConditionalOnProperty(value = "sms.name", havingValue = "aliyun")
public class AliSmsConfiguration {

	private final BaseRedis macroRedis;

	@Bean
	public AliSmsTemplate aliSmsTemplate(SmsProperties smsProperties) {
		IClientProfile profile = DefaultProfile.getProfile(smsProperties.getRegionId(), smsProperties.getAccessKey(), smsProperties.getSecretKey());
		IAcsClient acsClient = new DefaultAcsClient(profile);
		return new AliSmsTemplate(smsProperties, acsClient, macroRedis);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy