Class OpenSms
java.lang.Object
cloud.opencode.base.sms.OpenSms
Open SMS
开放短信
Main facade for SMS operations.
短信操作的主要门面。
Features | 主要功能:
- Send SMS by phone number and content - 通过手机号和内容发送短信
- Template-based SMS sending - 基于模板的短信发送
- Multiple provider support (Aliyun, Tencent, Huawei, etc.) - 多服务商支持
- Console mock mode for testing - 控制台模拟模式用于测试
Usage Examples | 使用示例:
// Create from config
OpenSms sms = OpenSms.of(SmsConfig.builder()
.providerType(SmsProviderType.ALIYUN)
.accessKey("key").secretKey("secret")
.signName("MyApp").build());
// Send simple SMS
SmsResult result = sms.send("13800138000", "Your code is 1234");
// Console mock for testing
OpenSms consoleSms = OpenSms.console();
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
- Null-safe: No (requires non-null provider) - 空值安全: 否(需要非空提供商)
- Since:
- JDK 25, opencode-base-sms V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close provider 关闭提供商static OpenSmsconsole()Create console mock instance 创建控制台模拟实例Get provider 获取提供商Get template registry 获取模板注册表booleanCheck if provider is available 检查提供商是否可用static OpenSmsCreate from config 从配置创建static OpenSmsof(SmsProvider provider) Create from provider 从提供商创建registerTemplate(SmsTemplate template) Register template 注册模板registerTemplate(String id, String content) Register template 注册模板send(SmsMessage message) Send SMS message 发送短信消息Send SMS 发送短信sendBatch(List<SmsMessage> messages) Send batch SMS 批量发送短信Send using template 使用模板发送Send template to multiple recipients 使用模板发送给多个收件人Send to multiple recipients 发送给多个收件人
-
Method Details
-
of
-
of
Create from provider 从提供商创建- Parameters:
provider- the provider | 提供商- Returns:
- the OpenSms instance | OpenSms实例
-
console
Create console mock instance 创建控制台模拟实例- Returns:
- the OpenSms instance | OpenSms实例
-
send
-
send
Send SMS message 发送短信消息- Parameters:
message- the message | 消息- Returns:
- the result | 结果
-
sendBatch
Send batch SMS 批量发送短信- Parameters:
messages- the messages | 消息列表- Returns:
- the results | 结果列表
-
sendToAll
-
registerTemplate
-
registerTemplate
Register template 注册模板- Parameters:
template- the template | 模板- Returns:
- this | 此对象
-
sendTemplate
-
sendTemplateToAll
public List<SmsResult> sendTemplateToAll(String templateId, List<String> phoneNumbers, Map<String, String> variables) Send template to multiple recipients 使用模板发送给多个收件人- Parameters:
templateId- the template ID | 模板IDphoneNumbers- the phone numbers | 手机号码列表variables- the variables | 变量- Returns:
- the results | 结果列表
-
getProvider
-
getTemplateRegistry
Get template registry 获取模板注册表- Returns:
- the registry | 注册表
-
isAvailable
public boolean isAvailable()Check if provider is available 检查提供商是否可用- Returns:
- true if available | 如果可用返回true
-
close
public void close()Close provider 关闭提供商
-