Class SmsTemplateRegistry
java.lang.Object
cloud.opencode.base.sms.template.SmsTemplateRegistry
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all templates 清除所有模板booleanCheck if template exists 检查模板是否存在Create message from template 从模板创建消息Get template as Optional 以Optional获取模板Get template by ID 按ID获取模板getAll()Get all templates 获取所有模板register(SmsTemplate template) Register template 注册模板Register template from content 从内容注册模板intsize()Get template count 获取模板数量unregister(String id) Unregister template 取消注册模板
-
Constructor Details
-
SmsTemplateRegistry
public SmsTemplateRegistry()
-
-
Method Details
-
register
Register template 注册模板- Parameters:
template- the template | 模板- Returns:
- this registry | 此注册表
-
register
Register template from content 从内容注册模板- Parameters:
id- the template ID | 模板IDcontent- the content | 内容- Returns:
- this registry | 此注册表
-
unregister
Unregister template 取消注册模板- Parameters:
id- the template ID | 模板ID- Returns:
- this registry | 此注册表
-
get
Get template by ID 按ID获取模板- Parameters:
id- the template ID | 模板ID- Returns:
- the template or null | 模板或null
-
find
Get template as Optional 以Optional获取模板- Parameters:
id- the template ID | 模板ID- Returns:
- the optional template | 可选模板
-
contains
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
-
createMessage
public SmsMessage createMessage(String templateId, String phoneNumber, Map<String, String> variables) Create message from template 从模板创建消息- Parameters:
templateId- the template ID | 模板IDphoneNumber- 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 清除所有模板
-