Class HttpSmsProvider

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

public class HttpSmsProvider extends Object implements SmsProvider
HTTP SMS Provider HTTP短信提供商

Generic HTTP-based SMS provider.

通用的基于HTTP的短信提供商。

Features | 主要功能:

  • Generic HTTP API integration - 通用HTTP API集成
  • Configurable authentication headers - 可配置认证头
  • Parallel batch sending - 并行批量发送

Usage Examples | 使用示例:

HttpSmsConfig config = HttpSmsConfig.builder()
    .apiUrl("https://sms-api.example.com/send")
    .appId("id").appKey("key").build();
HttpSmsProvider provider = new HttpSmsProvider(config);
SmsResult result = provider.send(SmsMessage.of("13800138000", "Hello"));

Security | 安全性:

  • Thread-safe: Yes (shared HttpClient, immutable config) - 线程安全: 是(共享HttpClient,不可变配置)
Since:
JDK 25, opencode-base-sms V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • HttpSmsProvider

      public HttpSmsProvider(HttpSmsConfig config)
      Create HTTP SMS provider 创建HTTP短信提供商
      Parameters:
      config - the config | 配置
  • Method Details

    • 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 | 结果列表
    • buildRequestBody

      protected String buildRequestBody(SmsMessage message)
      Build request body 构建请求体
      Parameters:
      message - the message | 消息
      Returns:
      the request body | 请求体
    • buildAuthHeaders

      protected String[] buildAuthHeaders()
      Build auth headers 构建认证头
      Returns:
      the headers | 头部
    • parseResponse

      protected SmsResult parseResponse(String body, int statusCode)
      Parse response 解析响应
      Parameters:
      body - the response body | 响应体
      statusCode - the status code | 状态码
      Returns:
      the result | 结果
    • 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

      protected HttpSmsConfig getConfig()
      Get config 获取配置
      Returns:
      the config | 配置
    • getHttpClient

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