Record Class SmsMessage

java.lang.Object
java.lang.Record
cloud.opencode.base.sms.message.SmsMessage
Record Components:
phoneNumber - the phone number | 手机号码
content - the message content | 消息内容
templateId - the template ID (optional) | 模板ID(可选)
variables - the template variables (optional) | 模板变量(可选)

public record SmsMessage(String phoneNumber, String content, String templateId, Map<String,String> variables) extends Record
SMS Message 短信消息

Represents an SMS message to be sent.

表示要发送的短信消息。

Features | 主要功能:

  • Content-based and template-based message creation - 基于内容和模板的消息创建
  • Defensive copy of template variables - 模板变量防御性复制
  • Builder pattern support - 构建器模式支持

Usage Examples | 使用示例:

SmsMessage msg = SmsMessage.of("13800138000", "Your code is 1234");
SmsMessage tpl = SmsMessage.ofTemplate("13800138000", "TPL_001",
    Map.of("code", "1234"));

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
Since:
JDK 25, opencode-base-sms V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • SmsMessage

      public SmsMessage(String phoneNumber, String content, String templateId, Map<String,String> variables)
      Creates an instance of a SmsMessage record class.
      Parameters:
      phoneNumber - the value for the phoneNumber record component
      content - the value for the content record component
      templateId - the value for the templateId record component
      variables - the value for the variables record component
  • Method Details

    • of

      public static SmsMessage of(String phoneNumber, String content)
      Create message with content 使用内容创建消息
      Parameters:
      phoneNumber - the phone number | 手机号码
      content - the content | 内容
      Returns:
      the message | 消息
    • ofTemplate

      public static SmsMessage ofTemplate(String phoneNumber, String templateId, Map<String,String> variables)
      Create message with template 使用模板创建消息
      Parameters:
      phoneNumber - the phone number | 手机号码
      templateId - the template ID | 模板ID
      variables - the variables | 变量
      Returns:
      the message | 消息
    • builder

      public static SmsMessage.Builder builder()
      Create builder 创建构建器
      Returns:
      the builder | 构建器
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • phoneNumber

      public String phoneNumber()
      Returns the value of the phoneNumber record component.
      Returns:
      the value of the phoneNumber record component
    • content

      public String content()
      Returns the value of the content record component.
      Returns:
      the value of the content record component
    • templateId

      public String templateId()
      Returns the value of the templateId record component.
      Returns:
      the value of the templateId record component
    • variables

      public Map<String,String> variables()
      Returns the value of the variables record component.
      Returns:
      the value of the variables record component