SmsConfiguration.java 1.7 KB
package com.diligrp.assistant.sms;

import com.diligrp.assistant.shared.mybatis.MybatisMapperSupport;
import com.diligrp.assistant.sms.pipeline.*;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("com.diligrp.assistant.sms")
@MapperScan(basePackages =  {"com.diligrp.assistant.sms.dao"}, markerInterface = MybatisMapperSupport.class)
public class SmsConfiguration {
    @Bean
    @ConfigurationProperties("sms")
    public SmsProperties smsProperties() {
        return new SmsProperties();
    }

    @Bean
    public SmsPipelineManager smsPipelineManager(SmsProperties properties) {
        SmsPipelineManager pipelineManager = new DefaultSmsPipelineManager();

        // TODO: 可利用数据库进行通道配置, 前期并没有必要
        SmsProperties.AliSms aliSms =  properties.getAlisms();
        if (aliSms != null) {
            SmsPipeline aliPipeline = new AliSmsPipeline(10, "阿里云短信服务通道", aliSms.getEndPoint(),
                aliSms.getAccessKeyId(), aliSms.getAccessKeySecret());
            pipelineManager.registerPipeline(aliPipeline);
        }

        SmsProperties.SmsChinese chinese = properties.getSmschinese();
        if (chinese != null) {
            SmsPipeline pipeline = new SmsChinesePipeline(20, "网建短信服务通道", chinese.getUri(),
                chinese.getUid(), chinese.getSecretKey());
            pipelineManager.registerPipeline(pipeline);
        }
        return pipelineManager;
    }
}