Class SmsTemplateRegistry

java.lang.Object
cloud.opencode.base.sms.template.SmsTemplateRegistry

public class SmsTemplateRegistry extends Object
SMS Template Registry 短信模板注册表

Registry for managing SMS templates.

管理短信模板的注册表。

Features | 主要功能:

  • Template registration and lookup - 模板注册和查找
  • Message creation from templates - 从模板创建消息
  • Fluent API with method chaining - 流式API方法链

Usage Examples | 使用示例:

SmsTemplateRegistry registry = new SmsTemplateRegistry();
registry.register("verify", "Your code is ${code}")
        .register("welcome", "Welcome, ${name}!");
SmsMessage msg = registry.createMessage("verify", "13800138000",
    Map.of("code", "1234"));

Security | 安全性:

  • Thread-safe: Yes (ConcurrentHashMap storage) - 线程安全: 是(ConcurrentHashMap存储)
Since:
JDK 25, opencode-base-sms V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • SmsTemplateRegistry

      public SmsTemplateRegistry()
  • Method Details

    • register

      public SmsTemplateRegistry register(SmsTemplate template)
      Register template 注册模板
      Parameters:
      template - the template | 模板
      Returns:
      this registry | 此注册表
    • register

      public SmsTemplateRegistry register(String id, String content)
      Register template from content 从内容注册模板
      Parameters:
      id - the template ID | 模板ID
      content - the content | 内容
      Returns:
      this registry | 此注册表
    • unregister

      public SmsTemplateRegistry unregister(String id)
      Unregister template 取消注册模板
      Parameters:
      id - the template ID | 模板ID
      Returns:
      this registry | 此注册表
    • get

      public SmsTemplate get(String id)
      Get template by ID 按ID获取模板
      Parameters:
      id - the template ID | 模板ID
      Returns:
      the template or null | 模板或null
    • find

      public Optional<SmsTemplate> find(String id)
      Get template as Optional 以Optional获取模板
      Parameters:
      id - the template ID | 模板ID
      Returns:
      the optional template | 可选模板
    • contains

      public boolean contains(String id)
      Check if template exists 检查模板是否存在
      Parameters:
      id - the template ID | 模板ID
      Returns:
      true if exists | 如果存在返回true
    • size

      public int size()
      Get template count 获取模板数量
      Returns:
      the count | 数量
    • getAll

      public Map<String, SmsTemplate> getAll()
      Get all templates 获取所有模板
      Returns:
      the templates | 模板
    • createMessage

      public SmsMessage createMessage(String templateId, String phoneNumber, Map<String,String> variables)
      Create message from template 从模板创建消息
      Parameters:
      templateId - the template ID | 模板ID
      phoneNumber - the phone number | 手机号码
      variables - the variables | 变量
      Returns:
      the message | 消息
      Throws:
      SmsTemplateException - if template not found or variables missing
    • clear

      public void clear()
      Clear all templates 清除所有模板