providers

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateCost

func EstimateCost(content string, smsType string) float64

EstimateCost 估算费用

func FormatPhone

func FormatPhone(phone string) string

FormatPhone 格式化手机号

Types

type BaseProvider

type BaseProvider struct {
	// contains filtered or unexported fields
}

BaseProvider 基础提供商实现

func (*BaseProvider) CreateProviderError

func (p *BaseProvider) CreateProviderError(code, message string, retryable bool) *ProviderError

CreateProviderError 创建提供商错误

func (*BaseProvider) GetName

func (p *BaseProvider) GetName() string

GetName 获取提供商名称

func (*BaseProvider) GetTimeout

func (p *BaseProvider) GetTimeout() time.Duration

GetTimeout 获取超时时间

func (*BaseProvider) SetTimeout

func (p *BaseProvider) SetTimeout(timeout time.Duration)

SetTimeout 设置超时时间

func (*BaseProvider) ValidateBatchRequest

func (p *BaseProvider) ValidateBatchRequest(req *BatchSMSRequest) error

ValidateBatchRequest 验证批量请求参数

func (*BaseProvider) ValidateRequest

func (p *BaseProvider) ValidateRequest(req *SendSMSRequest) error

ValidateRequest 验证请求参数

type BatchSMSRequest

type BatchSMSRequest struct {
	Requests []*SendSMSRequest `json:"requests"` // 短信请求列表
	BatchID  string            `json:"batch_id"` // 批次ID
}

BatchSMSRequest 批量发送短信请求

type BatchSMSResponse

type BatchSMSResponse struct {
	BatchID    string            `json:"batch_id"`    // 批次ID
	Total      int               `json:"total"`       // 总数
	Success    int               `json:"success"`     // 成功数
	Failed     int               `json:"failed"`      // 失败数
	Results    []*BatchSMSResult `json:"results"`     // 结果列表
	StartedAt  time.Time         `json:"started_at"`  // 开始时间
	FinishedAt time.Time         `json:"finished_at"` // 完成时间
	Cost       float64           `json:"cost"`        // 总费用
}

BatchSMSResponse 批量发送短信响应

type BatchSMSResult

type BatchSMSResult struct {
	Index        int        `json:"index"`                   // 索引
	Phone        string     `json:"phone"`                   // 手机号
	MessageID    string     `json:"message_id,omitempty"`    // 消息ID
	ProviderID   string     `json:"provider_id,omitempty"`   // 提供商消息ID
	Status       string     `json:"status"`                  // 状态
	Cost         float64    `json:"cost,omitempty"`          // 费用
	SentAt       *time.Time `json:"sent_at,omitempty"`       // 发送时间
	ErrorCode    string     `json:"error_code,omitempty"`    // 错误代码
	ErrorMessage string     `json:"error_message,omitempty"` // 错误消息
}

BatchSMSResult 批量发送结果

type ProviderError

type ProviderError struct {
	Code      string `json:"code"`      // 错误代码
	Message   string `json:"message"`   // 错误消息
	Provider  string `json:"provider"`  // 提供商
	Retryable bool   `json:"retryable"` // 是否可重试
}

ProviderError 提供商错误

func (*ProviderError) Error

func (e *ProviderError) Error() string

Error 实现error接口

func (*ProviderError) IsRetryable

func (e *ProviderError) IsRetryable() bool

IsRetryable 是否可重试

type ProviderFactory

type ProviderFactory interface {
	// CreateProvider 创建提供商实例
	CreateProvider(providerType string, config interface{}) (SMSProvider, error)

	// GetSupportedProviders 获取支持的提供商列表
	GetSupportedProviders() []string

	// ValidateProviderConfig 验证提供商配置
	ValidateProviderConfig(providerType string, config interface{}) error
}

ProviderFactory 提供商工厂接口

type QuerySMSRequest

type QuerySMSRequest struct {
	MessageID  string `json:"message_id,omitempty"`  // 消息ID
	ProviderID string `json:"provider_id,omitempty"` // 提供商消息ID
	Phone      string `json:"phone,omitempty"`       // 手机号
}

QuerySMSRequest 查询短信状态请求

type QuerySMSResponse

type QuerySMSResponse struct {
	MessageID    string            `json:"message_id"`              // 消息ID
	ProviderID   string            `json:"provider_id"`             // 提供商消息ID
	Phone        string            `json:"phone"`                   // 手机号
	Content      string            `json:"content"`                 // 短信内容
	Status       string            `json:"status"`                  // 状态
	SentAt       *time.Time        `json:"sent_at,omitempty"`       // 发送时间
	DeliveredAt  *time.Time        `json:"delivered_at,omitempty"`  // 送达时间
	FailedAt     *time.Time        `json:"failed_at,omitempty"`     // 失败时间
	ErrorCode    string            `json:"error_code,omitempty"`    // 错误代码
	ErrorMessage string            `json:"error_message,omitempty"` // 错误消息
	Cost         float64           `json:"cost,omitempty"`          // 费用
	Metadata     map[string]string `json:"metadata,omitempty"`      // 元数据
}

QuerySMSResponse 查询短信状态响应

type QuotaResponse

type QuotaResponse struct {
	Total     int64     `json:"total"`     // 总配额
	Used      int64     `json:"used"`      // 已使用
	Remaining int64     `json:"remaining"` // 剩余
	ResetAt   time.Time `json:"reset_at"`  // 重置时间
}

QuotaResponse 配额响应

type SMSProvider

type SMSProvider interface {
	// GetName 获取提供商名称
	GetName() string

	// SendSMS 发送单条短信
	SendSMS(ctx context.Context, req *SendSMSRequest) (*SendSMSResponse, error)

	// SendBatchSMS 批量发送短信
	SendBatchSMS(ctx context.Context, req *BatchSMSRequest) (*BatchSMSResponse, error)

	// QuerySMS 查询短信状态
	QuerySMS(ctx context.Context, req *QuerySMSRequest) (*QuerySMSResponse, error)

	// GetQuota 获取剩余配额
	GetQuota(ctx context.Context) (*QuotaResponse, error)

	// ValidateConfig 验证配置
	ValidateConfig() error

	// HealthCheck 健康检查
	HealthCheck(ctx context.Context) error
}

SMSProvider SMS提供商接口

type SendSMSRequest

type SendSMSRequest struct {
	Phone     string            `json:"phone"`               // 手机号
	Content   string            `json:"content"`             // 短信内容
	Sign      string            `json:"sign,omitempty"`      // 短信签名
	Type      string            `json:"type,omitempty"`      // 短信类型
	Priority  int               `json:"priority,omitempty"`  // 优先级
	Scheduled *time.Time        `json:"scheduled,omitempty"` // 定时发送时间
	Metadata  map[string]string `json:"metadata,omitempty"`  // 元数据
	MessageID string            `json:"message_id"`          // 消息ID
}

SendSMSRequest 发送短信请求

type SendSMSResponse

type SendSMSResponse struct {
	MessageID    string            `json:"message_id"`              // 消息ID
	Status       string            `json:"status"`                  // 状态
	ProviderID   string            `json:"provider_id"`             // 提供商消息ID
	Cost         float64           `json:"cost,omitempty"`          // 费用
	SentAt       time.Time         `json:"sent_at"`                 // 发送时间
	DeliveredAt  *time.Time        `json:"delivered_at,omitempty"`  // 送达时间
	ErrorCode    string            `json:"error_code,omitempty"`    // 错误代码
	ErrorMessage string            `json:"error_message,omitempty"` // 错误消息
	Metadata     map[string]string `json:"metadata,omitempty"`      // 元数据
}

SendSMSResponse 发送短信响应

type SpaceIoTConfig

type SpaceIoTConfig struct {
	BaseURL string        `json:"base_url"` // API基础URL
	Sign    string        `json:"sign"`     // 签名
	Key     string        `json:"key"`      // 密钥
	Timeout time.Duration `json:"timeout"`  // 超时时间
}

SpaceIoTConfig Space IoT配置

type SpaceIoTProvider

type SpaceIoTProvider struct {
	*BaseProvider
	// contains filtered or unexported fields
}

SpaceIoTProvider Space IoT SMS提供商实现

func NewSpaceIoTProvider

func NewSpaceIoTProvider(config *SpaceIoTConfig) *SpaceIoTProvider

NewSpaceIoTProvider 创建Space IoT提供商实例

func (*SpaceIoTProvider) GetQuota

func (p *SpaceIoTProvider) GetQuota(ctx context.Context) (*QuotaResponse, error)

GetQuota 获取剩余配额

func (*SpaceIoTProvider) HealthCheck

func (p *SpaceIoTProvider) HealthCheck(ctx context.Context) error

HealthCheck 健康检查

func (*SpaceIoTProvider) QuerySMS

QuerySMS 查询短信状态

func (*SpaceIoTProvider) SendBatchSMS

func (p *SpaceIoTProvider) SendBatchSMS(ctx context.Context, req *BatchSMSRequest) (*BatchSMSResponse, error)

SendBatchSMS 批量发送短信

func (*SpaceIoTProvider) SendSMS

SendSMS 发送单条短信

func (*SpaceIoTProvider) ValidateConfig

func (p *SpaceIoTProvider) ValidateConfig() error

ValidateConfig 验证配置

type SpaceIoTQueryRequest

type SpaceIoTQueryRequest struct {
	AccountName  string `json:"accountName"`  // 账户名称
	Phone        string `json:"phone"`        // 手机号
	Timestamp    string `json:"timestamp"`    // 时间戳
	RandomString string `json:"randomString"` // 随机字符串
	Sign         string `json:"sign"`         // 签名
}

SpaceIoTQueryRequest Space IoT查询请求

type SpaceIoTQueryResponse

type SpaceIoTQueryResponse struct {
	Code    int                      `json:"code"`    // 响应代码
	Message string                   `json:"message"` // 响应消息
	Data    *SpaceIoTQueryResultData `json:"data"`    // 响应数据
}

SpaceIoTQueryResponse Space IoT查询响应

type SpaceIoTQueryResultData

type SpaceIoTQueryResultData struct {
	Status      string `json:"status"`      // 状态
	SentAt      string `json:"sentAt"`      // 发送时间
	DeliveredAt string `json:"deliveredAt"` // 送达时间
	ErrorCode   string `json:"errorCode"`   // 错误代码
	ErrorMsg    string `json:"errorMsg"`    // 错误消息
}

SpaceIoTQueryResultData Space IoT查询结果数据

type SpaceIoTSendRequest

type SpaceIoTSendRequest struct {
	AccountName  string `json:"accountName"`  // 账户名称
	Phone        string `json:"phone"`        // 手机号
	Content      string `json:"content"`      // 短信内容
	Timestamp    string `json:"timestamp"`    // 时间戳
	RandomString string `json:"randomString"` // 随机字符串
	Sign         string `json:"sign"`         // 签名
}

SpaceIoTSendRequest Space IoT发送请求

type SpaceIoTSendResponse

type SpaceIoTSendResponse struct {
	Code    int    `json:"code"`    // 响应代码
	Message string `json:"message"` // 响应消息
	Data    bool   `json:"data"`    // 响应数据
}

SpaceIoTSendResponse Space IoT发送响应

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL