sms

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sms 提供短信服务集成,对标阿里云短信 SendSms API: 零第三方依赖,自实现阿里云 RPC 签名(HMAC-SHA1),适配标准接口语义。

Index

Constants

View Source
const (
	// DefaultEndpoint 阿里云短信服务地址。
	DefaultEndpoint = "https://dysmsapi.aliyuncs.com"
	// APIVersion 接口版本。
	APIVersion = "2017-05-25"
	// ActionSendSms 发送短信动作。
	ActionSendSms = "SendSms"
)

阿里云短信接口常量(对齐 dysmsapi.aliyuncs.com 2017-05-25)。

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client 短信客户端。

func NewClient

func NewClient(config Config) (*Client, error)

NewClient 创建短信客户端。

func (*Client) Send

func (c *Client) Send(ctx context.Context, request SendRequest) (*SendResponse, error)

Send 发送短信(对标阿里云 SendSms)。

type Config

type Config struct {
	// AccessKeyID 阿里云 AccessKey ID。
	AccessKeyID string
	// AccessKeySecret 阿里云 AccessKey Secret。
	AccessKeySecret string
	// SignName 短信签名(如「公司名」)。
	SignName string
	// TemplateCode 短信模板 Code(如 SMS_123456789)。
	TemplateCode string
	// Endpoint 服务地址;空时使用默认。
	Endpoint string
	// Timeout 请求超时(默认 10s)。
	Timeout time.Duration
}

Config 短信服务配置(阿里云 AccessKey)。

type SendRequest

type SendRequest struct {
	// PhoneNumbers 接收号码(单发一个;批量用逗号分隔多个,最多 1000)。
	PhoneNumbers string
	// SignName 签名(空时用 Config.SignName)。
	SignName string
	// TemplateCode 模板 Code(空时用 Config.TemplateCode)。
	TemplateCode string
	// TemplateParam 模板变量(如 {"code":"123456"});无变量可为 nil。
	TemplateParam map[string]string
	// OutId 外部流水号(回调定位用,可选)。
	OutId string
}

SendRequest 发送短信请求参数(对齐阿里云 SendSms)。

type SendResponse

type SendResponse struct {
	// Code 结果码(OK 为成功;失败为阿里云错误码,如 isv.MOBILE_NUMBER_ILLEGAL)。
	Code string `json:"Code"`
	// Message 描述。
	Message string `json:"Message"`
	// RequestID 请求 ID(排查用)。
	RequestID string `json:"RequestId"`
	// BizID 发送回执 ID(查询状态用)。
	BizID string `json:"BizId"`
}

SendResponse 发送结果(对齐阿里云返回)。

func (*SendResponse) IsSuccess

func (r *SendResponse) IsSuccess() bool

IsSuccess 是否发送成功。

Jump to

Keyboard shortcuts

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