Class AliSmsSender

java.lang.Object
cloud.opencode.base.sms.provider.AliSmsSender
All Implemented Interfaces:
SmsProvider

public class AliSmsSender extends Object implements 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:
  • Method Details

    • create

      public static AliSmsSender create(AliSmsSender.AliSmsConfig config)
      Create AliSmsSender instance 创建阿里云短信发送器实例
      Parameters:
      config - the configuration | 配置
      Returns:
      the sender instance | 发送器实例
    • send

      public SmsResult send(SmsMessage message)
      Description copied from interface: SmsProvider
      Send single SMS 发送单条短信
      Specified by:
      send in interface SmsProvider
      Parameters:
      message - the message | 消息
      Returns:
      the result | 结果
    • sendBatch

      public List<SmsResult> sendBatch(List<SmsMessage> messages)
      Description copied from interface: SmsProvider
      Send batch SMS 批量发送短信
      Specified by:
      sendBatch in interface SmsProvider
      Parameters:
      messages - the messages | 消息列表
      Returns:
      the results | 结果列表
    • getName

      public String getName()
      Description copied from interface: SmsProvider
      Get provider name 获取提供商名称
      Specified by:
      getName in interface SmsProvider
      Returns:
      the name | 名称
    • isAvailable

      public boolean isAvailable()
      Description copied from interface: SmsProvider
      Check if provider is available 检查提供商是否可用
      Specified by:
      isAvailable in interface SmsProvider
      Returns:
      true if available | 如果可用返回true
    • getConfig

      public AliSmsSender.AliSmsConfig getConfig()
      Get configuration 获取配置
      Returns:
      the config | 配置
    • getHttpClient

      protected HttpClient getHttpClient()
      Get shared HTTP client 获取共享HTTP客户端
      Returns:
      the HTTP client | HTTP客户端