sms

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2025 License: Apache-2.0 Imports: 38 Imported by: 0

README

📱 sms

一个功能强大的Go语言短信发送组件库,支持多家主流短信服务提供商的统一接口调用。

✨ 特性

  • 🔌 统一接口: 提供一致的API接口,支持多家短信服务提供商
  • 🌍 多服务商支持: 支持20+家国内外主流短信服务提供商
  • 🚀 简单易用: 简洁的API设计,快速集成到项目中
  • 🛡️ 类型安全: 完整的Go类型定义和错误处理
  • 📝 完整文档: 详细的中文注释和使用示例
  • 🧪 测试友好: 内置Mock客户端,方便单元测试

🏢 支持的服务提供商

国内服务商
  • 🇨🇳 阿里云短信 (Aliyun SMS)
  • 🇨🇳 腾讯云短信 (Tencent Cloud SMS)
  • 🇨🇳 百度云短信 (Baidu Cloud SMS)
  • 🇨🇳 华为云短信 (Huawei Cloud SMS)
  • 🇨🇳 火山引擎短信 (Volc Engine SMS)
  • 🇨🇳 UCloud短信 (UCloud SMS)
  • 🇨🇳 短信宝 (SmsBao SMS)
  • 🇨🇳 互亿无线 (Huyi SMS)
  • 🇨🇳 SUBMAIL
  • 🇨🇳 GCCPAY SMS
国际服务商
  • 🌍 Twilio
  • 🌍 Amazon SNS
  • 🌍 Microsoft Azure ACS
  • 🌍 Infobip
  • 🌍 Msg91
  • 🌍 Netgsm
  • 🌍 OSON SMS
  • 🌍 Uni SMS
测试工具
  • 🧪 Mock SMS (用于测试环境)

📦 安装

go get github.com/smart-unicom/sms

🚀 快速开始

基本用法
package main

import (
    "fmt"
    "github.com/smart-unicom/sms"
)

func main() {
    // 创建短信客户端
    client, err := sms.NewSmsProvider(
        sms.SMS_ALIYUN,     // 服务提供商
        "your-access-id",   // 访问ID
        "your-access-key",  // 访问密钥
        "your-sign-name",   // 短信签名
        "your-template-id", // 短信模板ID
    )
    if err != nil {
        panic(err)
    }

    // 发送短信
    params := map[string]string{
        "code": "123456", // 验证码
    }
    
    err = client.SendMessage(params, "+8613800138000")
    if err != nil {
        fmt.Printf("发送失败: %v\n", err)
        return
    }
    
    fmt.Println("短信发送成功!")
}

📖 详细使用示例

阿里云短信
package main

import (
    "github.com/smart-unicom/sms"
)

func main() {
    client, err := sms.NewSmsProvider(
        sms.SMS_ALIYUN,
        "LTAI5tCExxxxxxxxxxxxxx",    // 访问密钥ID
        "2alE91xxxxxxxxxxxxxxxxxxxxxx", // 访问密钥
        "测试签名",                      // 短信签名
        "SMS_123456789",              // 短信模板CODE
    )
    if err != nil {
        panic(err)
    }

    params := map[string]string{
        "code": "888888",
    }
    
    err = client.SendMessage(params, "+8613800138000")
    if err != nil {
        panic(err)
    }
}
腾讯云短信
package main

import (
    "github.com/smart-unicom/sms"
)

func main() {
    client, err := sms.NewSmsProvider(
        sms.SMS_TENCENT,
        "AKIDxxxxxxxxxxxxxxxxxxxxxx",   // 密钥ID
        "2E7Axxxxxxxxxxxxxxxxxxxxxx",   // 密钥
        "测试签名",                        // 短信签名
        "123456",                       // 短信模板ID
        "1400123456",                   // 短信应用ID
    )
    if err != nil {
        panic(err)
    }

    params := map[string]string{
        "0": "888888", // 腾讯云使用数字索引作为参数名
    }
    
    err = client.SendMessage(params, "+8613800138000")
    if err != nil {
        panic(err)
    }
}
Twilio短信
package main

import (
    "github.com/smart-unicom/sms"
)

func main() {
    client, err := sms.NewSmsProvider(
        sms.SMS_TWILIO,
        "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // 账户SID
        "your_auth_token",                    // 认证令牌
        "",                                    // 签名(Twilio不需要)
        "您的验证码是: %s",                      // 短信模板
    )
    if err != nil {
        panic(err)
    }

    params := map[string]string{
        "code": "888888",
    }
    
    // 注意:Twilio需要发送方号码作为第一个参数
    err = client.SendMessage(params, "+1234567890", "+8613800138000")
    if err != nil {
        panic(err)
    }
}
华为云短信
package main

import (
    "github.com/smart-unicom/sms"
)

func main() {
    client, err := sms.NewSmsProvider(
        sms.SMS_HUAWEI,
        "your-app-key",                     // 应用密钥
        "your-app-secret",                  // 应用秘密
        "测试签名",                           // 短信签名
        "8ff55eac1d0b478ab3c06c3c6a492300", // 短信模板ID
        "https://smsapi.cn-north-4.myhuaweicloud.com", // API地址
        "+8610690000",                      // 发送方号码
    )
    if err != nil {
        panic(err)
    }

    params := map[string]string{
        "code": "888888",
    }
    
    err = client.SendMessage(params, "+8613800138000")
    if err != nil {
        panic(err)
    }
}
Mock客户端(测试用)
package main

import (
    "github.com/smart-unicom/sms"
)

func main() {
    // Mock客户端不会实际发送短信,适用于测试环境
    client, err := sms.NewSmsProvider(
        sms.SMS_MOCK,
        "mock-access-id",
        "mock-access-key",
        "mock-sign",
        "mock-template",
    )
    if err != nil {
        panic(err)
    }

    params := map[string]string{
        "code": "888888",
    }
    
    // 总是返回成功,不会实际发送短信
    err = client.SendMessage(params, "+8613800138000")
    if err != nil {
        panic(err)
    }
    
    fmt.Println("Mock短信发送成功(未实际发送)")
}

🔧 API参考

创建客户端
func NewSmsProvider(provider string, accessId string, accessKey string, sign string, template string, other ...string) (SmsProvider, error)

参数说明:

  • provider: 服务提供商类型(使用预定义常量)
  • accessId: 访问ID/用户名
  • accessKey: 访问密钥/密码
  • sign: 短信签名
  • template: 短信模板ID或内容
  • other: 其他参数(根据不同服务商而定)
发送短信
SendMessage(param map[string]string, targetPhoneNumber ...string) error

参数说明:

  • param: 短信模板参数
  • targetPhoneNumber: 目标手机号码列表
服务提供商常量
const (
    SMS_ALIYUN   = "Aliyun_SMS"        // 阿里云短信
    SMS_TENCENT  = "Tencent_Cloud_SMS" // 腾讯云短信
    SMS_TWILIO   = "Twilio_SMS"        // Twilio短信
    SMS_AMAZON   = "Amazon_SNS"        // 亚马逊SNS
    SMS_AZURE    = "Azure_ACS"         // 微软Azure
    SMS_HUAWEI   = "Huawei_Cloud_SMS"  // 华为云短信
    SMS_MOCK     = "Mock SMS"          // 模拟短信
    // ... 更多常量
)

🧪 测试

运行所有测试:

go test -v ./...

运行特定测试:

go test -v -run TestMockSMS

🤝 贡献

欢迎提交Issue和Pull Request来帮助改进这个项目!

贡献指南
  1. Fork 这个仓库
  2. 创建你的特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交你的修改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 打开一个 Pull Request
代码规范

请遵循项目中的代码规范,确保:

  • 所有注释使用中文
  • 遵循Go语言命名约定
  • 添加适当的错误处理
  • 编写相应的测试用例

📄 许可证

本项目基于 Apache 2.0 许可证 开源。

🙏 致谢

感谢所有为这个项目做出贡献的开发者!


如果这个项目对你有帮助,请给我们一个 ⭐️!

Documentation

Overview

Package sms 阿里云短信服务实现

Package sms 亚马逊SNS短信服务实现

Package sms 微软Azure通信服务短信实现

Package sms 百度云短信服务实现

Package sms GCCPAY短信服务实现

Package sms 华为云短信服务实现

Package sms 互亿无线短信服务实现

Package sms Infobip短信服务实现

Package sms 模拟短信服务实现

Package sms Msg91短信服务实现

Package sms Netgsm短信服务实现

Package sms OSON短信服务实现

Package sms 短信服务提供商统一接口

Package sms 短信宝短信服务实现

Package sms SUBMAIL短信服务实现

Package sms 腾讯云短信服务实现

Package sms Twilio短信服务实现

Package sms UCloud短信服务实现

Package sms UniSMS短信服务实现

Package sms 火山引擎短信服务实现

Index

Constants

View Source
const (
	WSSE_HEADER_FORMAT = "UsernameToken Username=\"%s\",PasswordDigest=\"%s\",Nonce=\"%s\",Created=\"%s\"" // WSSE头格式
	AUTH_HEADER_VALUE  = "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""                    // 认证头值
)

华为云短信API相关常量

View Source
const (
	SMS_TWILIO  string = "Twilio_SMS"        // Twilio短信服务
	SMS_AMAZON  string = "Amazon_SNS"        // 亚马逊SNS短信服务
	SMS_AZURE   string = "Azure_ACS"         // 微软Azure通信服务
	SMS_MSG91   string = "Msg91_SMS"         // Msg91短信服务
	SMS_GCCPAY  string = "GCCPAY_SMS"        // GCCPAY短信服务
	SMS_INFOBIP string = "Infobip_SMS"       // Infobip短信服务
	SMS_SUBMAIL string = "SUBMAIL_SMS"       // SUBMAIL短信服务
	SMS_SMSBAO  string = "SmsBao_SMS"        // 短信宝服务
	SMS_ALIYUN  string = "Aliyun_SMS"        // 阿里云短信服务
	SMS_TENCENT string = "Tencent_Cloud_SMS" // 腾讯云短信服务
	SMS_BAIdU   string = "Baidu_Cloud_SMS"   // 百度云短信服务
	SMS_VOCL    string = "Volc_Engine_SMS"   // 火山引擎短信服务
	SMS_HUAWEI  string = "Huawei_Cloud_SMS"  // 华为云短信服务
	SMS_UCloud  string = "UCloud_SMS"        // UCloud短信服务
	SMS_HUYI    string = "Huyi_SMS"          // 互亿无线短信服务
	SMS_MOCK    string = "Mock SMS"          // 模拟短信服务
	SMS_NETGSM  string = "Netgsm_SMS"        // Netgsm短信服务
	SMS_OSONI   string = "OSON_SMS"          // OSON短信服务
	SMS_UNI     string = "Uni_SMS"           // Uni短信服务
)

短信服务提供商常量定义

Variables

This section is empty.

Functions

func GetMd5String

func GetMd5String(s string) string

GetMd5String 计算字符串的MD5哈希值 参数:

  • s: 待计算的字符串

返回:

  • string: MD5哈希值的十六进制字符串

func Md5

func Md5(str string) string

Md5 计算字符串的MD5哈希值 参数:

  • str: 待计算的字符串

返回:

  • string: MD5哈希值的十六进制字符串

func RandStringBytesCrypto

func RandStringBytesCrypto(n int) (string, error)

RandStringBytesCrypto 生成指定长度的随机字符串 参数:

  • n: 字节长度

返回:

  • string: Base64编码的随机字符串
  • error: 错误信息

Types

type ACSClient

type ACSClient struct {
	AccessToken string // 访问令牌
	Endpoint    string // 服务端点
	Message     string // 短信内容
	Sender      string // 发送方号码
}

ACSClient Azure通信服务短信客户端 封装Azure通信服务短信API调用

func GetACSClient

func GetACSClient(accessToken string, message string, other []string) (*ACSClient, error)

GetACSClient 创建Azure通信服务短信客户端 参数:

  • accessToken: Azure访问令牌
  • message: 短信内容
  • other: 其他参数([0]为端点,[1]为发送方号码)

返回:

  • *ACSClient: Azure通信服务短信客户端实例
  • error: 错误信息

func (*ACSClient) SendMessage

func (a *ACSClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数(当前未使用)
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type AliyunClient

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

AliyunClient 阿里云短信客户端 封装阿里云短信API调用

func GetAliyunClient

func GetAliyunClient(accessId string, accessKey string, sign string, template string) (*AliyunClient, error)

GetAliyunClient 创建阿里云短信客户端 参数:

  • accessId: 阿里云访问ID
  • accessKey: 阿里云访问密钥
  • sign: 短信签名
  • template: 短信模板ID

返回:

  • *AliyunClient: 阿里云短信客户端实例
  • error: 错误信息

func (*AliyunClient) SendMessage

func (c *AliyunClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type AliyunResult

type AliyunResult struct {
	RequestId string // 请求ID
	Message   string // 响应消息
}

AliyunResult 阿里云短信发送结果

type AmazonSNSClient

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

AmazonSNSClient 亚马逊SNS短信客户端 封装亚马逊SNS短信API调用

func GetAmazonSNSClient

func GetAmazonSNSClient(accessKeyId string, secretAccessKey string, template string, region []string) (*AmazonSNSClient, error)

GetAmazonSNSClient 创建亚马逊SNS短信客户端 参数:

  • accessKeyId: AWS访问密钥ID
  • secretAccessKey: AWS访问密钥
  • template: 短信模板
  • region: AWS区域列表

返回:

  • *AmazonSNSClient: 亚马逊SNS短信客户端实例
  • error: 错误信息

func (*AmazonSNSClient) SendMessage

func (a *AmazonSNSClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数(需要包含"code"字段)
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type BaiduClient

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

BaiduClient 百度云短信客户端 封装百度云短信API调用

func GetBceClient

func GetBceClient(accessId, accessKey, sign, template string, endpoint []string) (*BaiduClient, error)

GetBceClient 创建百度云短信客户端 参数:

  • accessId: 百度云访问ID
  • accessKey: 百度云访问密钥
  • sign: 短信签名ID
  • template: 短信模板ID
  • endpoint: 服务端点列表

返回:

  • *BaiduClient: 百度云短信客户端实例
  • error: 错误信息

func (*BaiduClient) SendMessage

func (c *BaiduClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数(需要包含"code"字段)
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type Destination

type Destination struct {
	To string `json:"to"` // 目标号码
}

Destination 目标结构体

type GCCPAYClient

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

GCCPAYClient GCCPAY短信客户端 封装GCCPAY短信API调用

func GetGCCPAYClient

func GetGCCPAYClient(clientname string, secret string, template string) (*GCCPAYClient, error)

GetGCCPAYClient 创建GCCPAY短信客户端 参数:

  • clientname: 客户端名称
  • secret: 客户端密钥
  • template: 短信模板

返回:

  • *GCCPAYClient: GCCPAY短信客户端实例
  • error: 错误信息

func (*GCCPAYClient) SendMessage

func (c *GCCPAYClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type HuaweiClient

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

HuaweiClient 华为云短信客户端 封装华为云短信API调用

func GetHuaweiClient

func GetHuaweiClient(accessId string, accessKey string, sign string, template string, other []string) (*HuaweiClient, error)

GetHuaweiClient 创建华为云短信客户端 参数:

  • accessId: 华为云访问ID
  • accessKey: 华为云访问密钥
  • sign: 短信签名
  • template: 短信模板ID
  • other: 其他参数([0]为API地址,[1]为发送方号码)

返回:

  • *HuaweiClient: 华为云短信客户端实例
  • error: 错误信息

func (*HuaweiClient) SendMessage

func (c *HuaweiClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参考文档: https://support.huaweicloud.com/intl/zh-cn/devg-msgsms/sms_04_0012.html 参数:

  • param: 短信模板参数(需要包含"code"字段)
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type HuyiClient

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

HuyiClient 互亿无线短信客户端 封装互亿无线短信API调用

func GetHuyiClient

func GetHuyiClient(appId string, appKey string, template string) (*HuyiClient, error)

GetHuyiClient 创建互亿无线短信客户端 参数:

  • appId: 应用ID
  • appKey: 应用密钥
  • template: 短信模板

返回:

  • *HuyiClient: 互亿无线短信客户端实例
  • error: 错误信息

func (*HuyiClient) SendMessage

func (hc *HuyiClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type InfobipClient

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

InfobipClient Infobip短信客户端 封装Infobip短信API调用

func GetInfobipClient

func GetInfobipClient(sender string, apiKey string, template string, baseUrl []string) (*InfobipClient, error)

GetInfobipClient 创建Infobip短信客户端 参数:

  • sender: 发送方标识
  • apiKey: API密钥
  • template: 短信模板
  • baseUrl: API基础URL列表

返回:

  • *InfobipClient: Infobip短信客户端实例
  • error: 错误信息

func (*InfobipClient) SendMessage

func (c *InfobipClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type InfobipConfigService

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

InfobipConfigService Infobip配置服务

type Message

type Message struct {
	From         string        `json:"from"`         // 发送方
	Destinations []Destination `json:"destinations"` // 目标列表
	Text         string        `json:"text"`         // 消息内容
}

Message 消息结构体

type MessageData

type MessageData struct {
	Messages []Message `json:"messages"` // 消息列表
}

MessageData 消息数据结构体

type Mocker

type Mocker struct{}

Mocker 模拟短信客户端 用于测试环境,不实际发送短信

func NewMocker

func NewMocker(accessId, accessKey, sign, templateId string, smsAccount []string) (*Mocker, error)

NewMocker 创建模拟短信客户端 参数:

  • accessId: 访问ID(模拟用,不实际使用)
  • accessKey: 访问密钥(模拟用,不实际使用)
  • sign: 短信签名(模拟用,不实际使用)
  • templateId: 短信模板ID(模拟用,不实际使用)
  • smsAccount: 短信账户(模拟用,不实际使用)

返回:

  • *Mocker: 模拟短信客户端实例
  • error: 错误信息

func (*Mocker) SendMessage

func (m *Mocker) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 模拟发送短信 参数:

  • param: 短信模板参数(不实际使用)
  • targetPhoneNumber: 目标手机号码列表(不实际使用)

返回:

  • error: 始终返回nil(模拟成功)

type Msg91Client

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

Msg91Client Msg91短信客户端 封装Msg91短信API调用

func GetMsg91Client

func GetMsg91Client(senderId string, authKey string, templateId string) (*Msg91Client, error)

GetMsg91Client 创建Msg91短信客户端 参数:

  • senderId: 发送方ID
  • authKey: 认证密钥
  • templateId: 模板ID

返回:

  • *Msg91Client: Msg91短信客户端实例
  • error: 错误信息

func (*Msg91Client) SendMessage

func (m *Msg91Client) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type NetgsmClient

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

NetgsmClient Netgsm短信客户端 封装Netgsm短信API调用

func GetNetgsmClient

func GetNetgsmClient(accessId, accessKey, sign, template string) (*NetgsmClient, error)

GetNetgsmClient 创建Netgsm短信客户端 参数:

  • accessId: 访问ID
  • accessKey: 访问密钥
  • sign: 短信签名
  • template: 短信模板

返回:

  • *NetgsmClient: Netgsm短信客户端实例
  • error: 错误信息

func (*NetgsmClient) SendMessage

func (c *NetgsmClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type NetgsmResponse

type NetgsmResponse struct {
	Code  string `xml:"main>code"`  // 响应代码
	JobId string `xml:"main>jobId"` // 任务ID
	Error string `xml:"main>error"` // 错误信息
}

NetgsmResponse Netgsm响应结构体

type OsonClient

type OsonClient struct {
	Endpoint         string // API端点
	SenderId         string // 发送方ID
	SecretAccessHash string // 访问密钥哈希
	Sign             string // 短信签名
	Message          string // 短信内容
}

OsonClient OSON短信客户端 封装OSON短信API调用

func GetOsonClient

func GetOsonClient(senderId, secretAccessHash, sign, message string) (*OsonClient, error)

GetOsonClient 创建OSON短信客户端 参数:

  • senderId: 发送方ID
  • secretAccessHash: 访问密钥哈希
  • sign: 短信签名
  • message: 短信内容

返回:

  • *OsonClient: OSON短信客户端实例
  • error: 错误信息

func (*OsonClient) SendMessage

func (c *OsonClient) SendMessage(param map[string]string, targetPhoneNumber ...string) (err error)

SendMessage 发送短信 参数:

  • param: 短信模板参数
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type OsonResponse

type OsonResponse struct {
	Status        string    `json:"status"`          // 状态 (ok)
	Timestamp     time.Time `json:"timestamp"`       // 时间戳 (2017-07-07 16:58:12)
	TxnId         string    `json:"txn_id"`          // 交易ID
	MsgId         uint      `json:"msg_id"`          // 消息ID (40127)
	SmscMsgId     string    `json:"smsc_msg_id"`     // SMSC消息ID
	SmscMsgStatus string    `json:"smsc_msg_status"` // SMSC消息状态
	SmscMsgParts  string    `json:"smsc_msg_parts"`  // SMSC消息部分
}

OsonResponse OSON响应结构体

type SmsBaoClient

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

SmsBaoClient 短信宝客户端 封装短信宝API调用

func GetSmsbaoClient

func GetSmsbaoClient(username string, apikey string, sign string, template string, other []string) (*SmsBaoClient, error)

GetSmsbaoClient 创建短信宝客户端 参数:

  • username: 短信宝用户名
  • apikey: 短信宝API密钥
  • sign: 短信签名
  • template: 短信模板
  • other: 其他参数([0]为商品ID,可选)

返回:

  • *SmsBaoClient: 短信宝客户端实例
  • error: 错误信息

func (*SmsBaoClient) SendMessage

func (c *SmsBaoClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数(需要包含"code"字段)
  • targetPhoneNumber: 目标手机号码列表(仅支持中国大陆号码)

返回:

  • error: 错误信息

type SmsProvider

type SmsProvider interface {
	// SendMessage 发送短信
	// 参数:
	//   - param: 短信模板参数
	//   - targetPhoneNumber: 目标手机号码列表
	// 返回:
	//   - error: 错误信息
	SendMessage(param map[string]string, targetPhoneNumber ...string) error
}

SmsProvider 短信服务提供商接口 定义了发送短信的统一接口

func NewSmsProvider

func NewSmsProvider(provider string, accessId string, accessKey string, sign string, template string, other ...string) (SmsProvider, error)

NewSmsProvider 创建短信服务提供商实例 参数:

  • provider: 服务提供商类型
  • accessId: 访问ID
  • accessKey: 访问密钥
  • sign: 短信签名
  • template: 短信模板
  • other: 其他参数

返回:

  • SmsProvider: 短信服务提供商实例
  • error: 错误信息

type SmsService

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

SmsService 短信服务

type SubmailClient

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

SubmailClient SUBMAIL短信客户端 封装SUBMAIL短信API调用

func GetSubmailClient

func GetSubmailClient(appid string, signature string, project string) (*SubmailClient, error)

GetSubmailClient 创建SUBMAIL短信客户端 参数:

  • appid: 应用ID
  • signature: 签名
  • project: 项目标识

返回:

  • *SubmailClient: SUBMAIL短信客户端实例
  • error: 错误信息

func (*SubmailClient) SendMessage

func (c *SubmailClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type SubmailResult

type SubmailResult struct {
	Status string `json:"status"` // 状态
	Code   int    `json:"code"`   // 状态码
	Msg    string `json:"msg"`    // 消息
}

SubmailResult SUBMAIL响应结果结构体

type TencentClient

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

TencentClient 腾讯云短信客户端 封装腾讯云短信API调用

func GetTencentClient

func GetTencentClient(accessId string, accessKey string, sign string, templateId string, appId []string) (*TencentClient, error)

GetTencentClient 创建腾讯云短信客户端 参数:

  • accessId: 腾讯云访问ID
  • accessKey: 腾讯云访问密钥
  • sign: 短信签名
  • templateId: 短信模板ID
  • appId: 应用ID列表

返回:

  • *TencentClient: 腾讯云短信客户端实例
  • error: 错误信息

func (*TencentClient) SendMessage

func (c *TencentClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数(按索引顺序:"0", "1", "2"...)
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type TwilioClient

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

TwilioClient Twilio短信客户端 封装Twilio短信API调用

func GetTwilioClient

func GetTwilioClient(accessId string, accessKey string, template string) (*TwilioClient, error)

GetTwilioClient 创建Twilio短信客户端 参数:

  • accessId: Twilio账户SID
  • accessKey: Twilio认证令牌
  • template: 短信模板

返回:

  • *TwilioClient: Twilio短信客户端实例
  • error: 错误信息

func (*TwilioClient) SendMessage

func (c *TwilioClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 注意: targetPhoneNumber[0]是发送方号码,因此targetPhoneNumber至少需要两个参数 参数:

  • param: 短信模板参数(需要包含"code"字段)
  • targetPhoneNumber: 手机号码列表([0]为发送方,[1:]为接收方)

返回:

  • error: 错误信息

type UcloudClient

type UcloudClient struct {
	ProjectId  string // 项目ID
	PrivateKey string // 私钥
	PublicKey  string // 公钥
	Sign       string // 短信签名
	Template   string // 短信模板ID
	// contains filtered or unexported fields
}

UcloudClient UCloud短信客户端 封装UCloud短信API调用

func GetUcloudClient

func GetUcloudClient(publicKey string, privateKey string, sign string, template string, projectId []string) (*UcloudClient, error)

GetUcloudClient 创建UCloud短信客户端 参数:

  • publicKey: UCloud公钥
  • privateKey: UCloud私钥
  • sign: 短信签名
  • template: 短信模板ID
  • projectId: 项目ID列表

返回:

  • *UcloudClient: UCloud短信客户端实例
  • error: 错误信息

func (*UcloudClient) SendMessage

func (c *UcloudClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数(需要包含"code"字段)
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type UnismsClient

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

UnismsClient UniSMS短信客户端 封装UniSMS短信API调用

func GetUnismsClient

func GetUnismsClient(accessId string, accessKey string, signature string, templateId string) (*UnismsClient, error)

GetUnismsClient 创建UniSMS短信客户端 参数:

  • accessId: 访问ID
  • accessKey: 访问密钥
  • signature: 短信签名
  • templateId: 短信模板ID

返回:

  • *UnismsClient: UniSMS短信客户端实例
  • error: 错误信息

func (*UnismsClient) SendMessage

func (c *UnismsClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

type VolcClient

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

VolcClient 火山引擎短信客户端 封装火山引擎短信API调用

func GetVolcClient

func GetVolcClient(accessId, accessKey, sign, templateId string, smsAccount []string) (*VolcClient, error)

GetVolcClient 创建火山引擎短信客户端 参数:

  • accessId: 火山引擎访问ID
  • accessKey: 火山引擎访问密钥
  • sign: 短信签名
  • templateId: 短信模板ID
  • smsAccount: 短信账户列表

返回:

  • *VolcClient: 火山引擎短信客户端实例
  • error: 错误信息

func (*VolcClient) SendMessage

func (c *VolcClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error

SendMessage 发送短信 参数:

  • param: 短信模板参数
  • targetPhoneNumber: 目标手机号码列表

返回:

  • error: 错误信息

Jump to

Keyboard shortcuts

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