Class AliSmsSender
java.lang.Object
cloud.opencode.base.sms.provider.AliSmsSender
- All Implemented Interfaces:
SmsProvider
Aliyun SMS Sender
阿里云短信发送器
SMS provider implementation for Aliyun (Alibaba Cloud) SMS service. Uses HMAC-SHA1 signature algorithm for API authentication.
阿里云短信服务的短信提供商实现。 使用HMAC-SHA1签名算法进行API认证。
Features | 主要功能:
- HMAC-SHA1 API authentication - HMAC-SHA1 API认证
- Template-based SMS sending - 基于模板的短信发送
- Batch SMS sending - 批量短信发送
- Virtual thread HTTP client - 虚拟线程HTTP客户端
Example usage:
var config = new AliSmsSender.AliSmsConfig(
"your-access-key-id",
"your-access-key-secret",
"YourSignName",
"cn-hangzhou"
);
var sender = AliSmsSender.create(config);
var result = sender.send(SmsMessage.ofTemplate(
"13800138000",
"SMS_123456789",
Map.of("code", "123456")
));
Usage Examples | 使用示例:
var config = new AliSmsSender.AliSmsConfig(
"your-access-key-id",
"your-access-key-secret",
"YourSignName",
"cn-hangzhou"
);
var sender = AliSmsSender.create(config);
var result = sender.send(SmsMessage.ofTemplate(
"13800138000",
"SMS_123456789",
Map.of("code", "123456")
));
Security | 安全性:
- Thread-safe: Yes (immutable config, shared HttpClient) - 线程安全: 是(不可变配置,共享HttpClient)
- Since:
- JDK 25, opencode-base-sms V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAliyun SMS Configuration 阿里云短信配置 -
Method Summary
Modifier and TypeMethodDescriptionstatic AliSmsSendercreate(AliSmsSender.AliSmsConfig config) Create AliSmsSender instance 创建阿里云短信发送器实例Get configuration 获取配置protected HttpClientGet shared HTTP client 获取共享HTTP客户端getName()Get provider name 获取提供商名称booleanCheck if provider is available 检查提供商是否可用send(SmsMessage message) Send single SMS 发送单条短信sendBatch(List<SmsMessage> messages) Send batch SMS 批量发送短信Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface SmsProvider
close
-
Method Details
-
create
Create AliSmsSender instance 创建阿里云短信发送器实例- Parameters:
config- the configuration | 配置- Returns:
- the sender instance | 发送器实例
-
send
Description copied from interface:SmsProviderSend single SMS 发送单条短信- Specified by:
sendin interfaceSmsProvider- Parameters:
message- the message | 消息- Returns:
- the result | 结果
-
sendBatch
Description copied from interface:SmsProviderSend batch SMS 批量发送短信- Specified by:
sendBatchin interfaceSmsProvider- Parameters:
messages- the messages | 消息列表- Returns:
- the results | 结果列表
-
getName
Description copied from interface:SmsProviderGet provider name 获取提供商名称- Specified by:
getNamein interfaceSmsProvider- Returns:
- the name | 名称
-
isAvailable
public boolean isAvailable()Description copied from interface:SmsProviderCheck if provider is available 检查提供商是否可用- Specified by:
isAvailablein interfaceSmsProvider- Returns:
- true if available | 如果可用返回true
-
getConfig
-
getHttpClient
Get shared HTTP client 获取共享HTTP客户端- Returns:
- the HTTP client | HTTP客户端
-