book-api/maku-boot-system/src/main/java/net/maku/sms/SmsContext.java

36 lines
1.2 KiB
Java
Raw Normal View History

2024-06-25 17:16:49 +08:00
package net.maku.sms;
2022-08-20 14:19:22 +08:00
2022-08-31 11:22:15 +08:00
import net.maku.framework.common.exception.ServerException;
2024-06-25 17:16:49 +08:00
import net.maku.sms.config.SmsConfig;
import net.maku.system.enums.SmsPlatformEnum;
2022-08-20 14:19:22 +08:00
import java.util.Map;
/**
2022-08-20 19:11:09 +08:00
* 短信 Context
2022-08-20 14:19:22 +08:00
*
* @author 阿沐 babamu@126.com
2023-02-21 16:44:04 +08:00
* <a href="https://maku.net">MAKU</a>
2022-08-20 14:19:22 +08:00
*/
public class SmsContext {
private final SmsStrategy smsStrategy;
public SmsContext(SmsConfig config) {
2022-08-20 19:11:09 +08:00
if (config.getPlatform() == SmsPlatformEnum.ALIYUN.getValue()) {
2022-08-20 14:19:22 +08:00
this.smsStrategy = new AliyunSmsStrategy(config);
2022-08-20 22:39:21 +08:00
} else if (config.getPlatform() == SmsPlatformEnum.TENCENT.getValue()) {
this.smsStrategy = new TencentSmsStrategy(config);
2022-08-20 19:11:09 +08:00
} else if (config.getPlatform() == SmsPlatformEnum.QINIU.getValue()) {
this.smsStrategy = new QiniuSmsStrategy(config);
} else if (config.getPlatform() == SmsPlatformEnum.HUAWEI.getValue()) {
this.smsStrategy = new HuaweiSmsStrategy(config);
} else {
2022-08-31 11:22:15 +08:00
throw new ServerException("未知的短信平台");
2022-08-20 14:19:22 +08:00
}
}
public void send(String mobile, Map<String, String> params) {
smsStrategy.send(mobile, params);
}
}