forked from kidgrow-microservices-platform

zhaoxiaohao
2020-05-22 f21c78ae0e3c410c6ba5be77277b5b491aca3af1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.kidgrow.sms.aliyun.config;
 
import com.kidgrow.sms.client.SmsClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
 *
 * @Description: 阿里云 SMS 自动配置<br>
 * @Project: <br>
 * @CreateDate: Created in 2020/2/17 09:11 <br>
 * @Author: <a href="4345453@kidgrow.com">liuke</a>
 */
@Configuration
@ConditionalOnClass(name = "com.aliyuncs.IAcsClient")
@EnableConfigurationProperties(SmsProperties.class)
public class SmsAutoConfiguration {
    private final SmsProperties smsProperties;
 
    public SmsAutoConfiguration(final SmsProperties smsProperties) {
        this.smsProperties = smsProperties;
    }
 
    /**
     * Configuration SmsClient bean.
     *
     * @return the sms client
     */
    @Bean
    @ConditionalOnMissingBean
    public SmsClient smsClient() {
        if (this.smsProperties.getTemplates() == null) {
            return new SmsClient(this.smsProperties.getAccessKeyId(), this.smsProperties.getAccessKeySecret());
        } else {
            return new SmsClient(
                    this.smsProperties.getAccessKeyId(),
                    this.smsProperties.getAccessKeySecret(),
                    this.smsProperties.getTemplates());
        }
    }
}