Record Class SmsResult

java.lang.Object
java.lang.Record
cloud.opencode.base.sms.message.SmsResult
Record Components:
success - whether send succeeded | 是否发送成功
messageId - the message ID | 消息ID
phoneNumber - the phone number | 手机号码
errorCode - the error code if failed | 失败时的错误码
errorMessage - the error message if failed | 失败时的错误消息
timestamp - the timestamp | 时间戳

public record SmsResult(boolean success, String messageId, String phoneNumber, String errorCode, String errorMessage, Instant timestamp) extends Record
SMS Result 短信结果

Result of sending an SMS message.

发送短信消息的结果。

Features | 主要功能:

  • Success/failure status with message ID - 成功/失败状态及消息ID
  • Error code and message for failures - 失败时的错误码和消息
  • Factory methods for success and failure - 成功和失败的工厂方法

Usage Examples | 使用示例:

SmsResult ok = SmsResult.success("msg123", "13800138000");
SmsResult fail = SmsResult.failure("13800138000", "1001", "Send failed");
boolean sent = ok.success(); // true

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

    • SmsResult

      public SmsResult(boolean success, String messageId, String phoneNumber, String errorCode, String errorMessage, Instant timestamp)
      Creates an instance of a SmsResult record class.
      Parameters:
      success - the value for the success record component
      messageId - the value for the messageId record component
      phoneNumber - the value for the phoneNumber record component
      errorCode - the value for the errorCode record component
      errorMessage - the value for the errorMessage record component
      timestamp - the value for the timestamp record component
  • Method Details

    • success

      public static SmsResult success(String messageId, String phoneNumber)
      Create success result 创建成功结果
      Parameters:
      messageId - the message ID | 消息ID
      phoneNumber - the phone number | 手机号码
      Returns:
      the result | 结果
    • failure

      public static SmsResult failure(String phoneNumber, String errorCode, String errorMessage)
      Create failure result 创建失败结果
      Parameters:
      phoneNumber - the phone number | 手机号码
      errorCode - the error code | 错误码
      errorMessage - the error message | 错误消息
      Returns:
      the result | 结果
    • isFailed

      public boolean isFailed()
      Check if failed 检查是否失败
      Returns:
      true if failed | 如果失败返回true
    • success

      public static SmsResult success(String messageId)
      Create success result without phone 创建不带手机号的成功结果
      Parameters:
      messageId - the message ID | 消息ID
      Returns:
      the result | 结果
    • failure

      public static SmsResult failure(String errorCode, String errorMessage)
      Create failure result without phone 创建不带手机号的失败结果
      Parameters:
      errorCode - the error code | 错误码
      errorMessage - the error message | 错误消息
      Returns:
      the result | 结果
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • success

      public boolean success()
      Returns the value of the success record component.
      Returns:
      the value of the success record component
    • messageId

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

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

      public String errorCode()
      Returns the value of the errorCode record component.
      Returns:
      the value of the errorCode record component
    • errorMessage

      public String errorMessage()
      Returns the value of the errorMessage record component.
      Returns:
      the value of the errorMessage record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component