sms

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPhone    = errors.New("sms: invalid phone number")
	ErrSendFailed      = errors.New("sms: send failed")
	ErrRateLimitExceed = errors.New("sms: rate limit exceeded")
)

Functions

func GenerateCode

func GenerateCode() string

GenerateCode 生成6位验证码

Types

type AliyunProvider

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

AliyunProvider 阿里云短信提供商

func NewAliyunProvider

func NewAliyunProvider(config Config) *AliyunProvider

NewAliyunProvider 创建阿里云提供商

func (*AliyunProvider) Send

func (p *AliyunProvider) Send(msg *Message) error

Send 发送短信

func (*AliyunProvider) SendBatch

func (p *AliyunProvider) SendBatch(messages []*Message) error

SendBatch 批量发送

type CodeEntry

type CodeEntry struct {
	Code      string
	ExpiresAt time.Time
	Attempts  int
}

CodeEntry 验证码条目

type Config

type Config struct {
	Provider  string // 提供商: aliyun, tencent, twilio
	AccessKey string
	SecretKey string
	SignName  string // 签名
	Region    string // 区域
}

Config 短信配置

type Message

type Message struct {
	Phone      string
	TemplateID string
	Params     map[string]string
	Content    string // 纯文本内容(某些提供商支持)
}

Message 短信消息

type Provider

type Provider interface {
	Send(msg *Message) error
	SendBatch(messages []*Message) error
}

Provider 短信提供商接口

type SMS

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

SMS 短信发送器

func NewSMS

func NewSMS(config Config) (*SMS, error)

NewSMS 创建短信发送器

func (*SMS) Send

func (s *SMS) Send(msg *Message) error

Send 发送短信

func (*SMS) SendBatch

func (s *SMS) SendBatch(messages []*Message) error

SendBatch 批量发送

func (*SMS) SendVerificationCode

func (s *SMS) SendVerificationCode(phone, code string) error

SendVerificationCode 发送验证码

type TencentProvider

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

TencentProvider 腾讯云短信提供商

func NewTencentProvider

func NewTencentProvider(config Config) *TencentProvider

NewTencentProvider 创建腾讯云提供商

func (*TencentProvider) Send

func (p *TencentProvider) Send(msg *Message) error

Send 发送短信

func (*TencentProvider) SendBatch

func (p *TencentProvider) SendBatch(messages []*Message) error

SendBatch 批量发送

type TwilioProvider

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

TwilioProvider Twilio 短信提供商

func NewTwilioProvider

func NewTwilioProvider(config Config) *TwilioProvider

NewTwilioProvider 创建 Twilio 提供商

func (*TwilioProvider) Send

func (p *TwilioProvider) Send(msg *Message) error

Send 发送短信

func (*TwilioProvider) SendBatch

func (p *TwilioProvider) SendBatch(messages []*Message) error

SendBatch 批量发送

type VerificationCodeCache

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

VerificationCodeCache 验证码缓存

func NewVerificationCodeCache

func NewVerificationCodeCache() *VerificationCodeCache

NewVerificationCodeCache 创建验证码缓存

func (*VerificationCodeCache) Set

func (c *VerificationCodeCache) Set(phone, code string, ttl time.Duration)

Set 设置验证码

func (*VerificationCodeCache) Verify

func (c *VerificationCodeCache) Verify(phone, code string) error

Verify 验证验证码

Jump to

Keyboard shortcuts

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