SmsConfiguration.java
1.7 KB
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
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;
}
}