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
- func GetMd5String(s string) string
- func Md5(str string) string
- func RandStringBytesCrypto(n int) (string, error)
- type ACSClient
- type AliyunClient
- type AliyunResult
- type AmazonSNSClient
- type BaiduClient
- type Destination
- type GCCPAYClient
- type HuaweiClient
- type HuyiClient
- type InfobipClient
- type InfobipConfigService
- type Message
- type MessageData
- type Mocker
- type Msg91Client
- type NetgsmClient
- type NetgsmResponse
- type OsonClient
- type OsonResponse
- type SmsBaoClient
- type SmsProvider
- type SmsService
- type SubmailClient
- type SubmailResult
- type TencentClient
- type TwilioClient
- type UcloudClient
- type UnismsClient
- type VolcClient
Constants ¶
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相关常量
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 RandStringBytesCrypto ¶
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 ¶
GetACSClient 创建Azure通信服务短信客户端 参数:
- accessToken: Azure访问令牌
- message: 短信内容
- other: 其他参数([0]为端点,[1]为发送方号码)
返回:
- *ACSClient: Azure通信服务短信客户端实例
- 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 ¶
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 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 模拟短信客户端 用于测试环境,不实际发送短信
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: 错误信息