Documentation
¶
Index ¶
- Constants
- Variables
- func Base64Encode(text string) string
- func GatewayName(gateway IGateway) string
- func GetPhoneNumber(number IPhoneNumber) string
- func IsZero(s any) bool
- func Md5String(text string) string
- func Rand(min, max int) int
- func RandLetterString(lenNum int) string
- func RandNumString(lenNum int) string
- func RandString(lenNum int) string
- func RandomBytes(length int) ([]byte, error)
- func RandomInt(min, max int) (int, error)
- func ReplaceMapStrings(s string, repl MapStrings) string
- func ReplaceMapStringsForStringIndex(s, old string, news MapStrings) string
- func Sha1String(text string) string
- func Sha256String(text string) string
- func Sleep(t int64)
- func Time() int64
- func TimeString() string
- func URLEncode(text string) string
- func Uniqid(prefix string) string
- func Usleep(t int64)
- type ClientResult
- type GatewayMap
- type GoSMS
- type HashMap
- type IGateway
- type IMessage
- type IParser
- type IPhoneNumber
- type Lock
- type MapStringAny
- func (maps MapStringAny) Exist(k string) bool
- func (maps MapStringAny) Get(k string, dv any) any
- func (maps MapStringAny) JsonUnmarshal(v any) error
- func (maps MapStringAny) Set(k string, v any)
- func (maps MapStringAny) SetForce(k string, v any, force bool)
- func (maps MapStringAny) ToIMessage() IMessage
- func (maps MapStringAny) ToJson() (string, error)
- func (maps MapStringAny) Verify(mustKey []string) MapStrings
- type MapStrings
- func (maps MapStrings) Delete(k string)
- func (maps MapStrings) Exist(k string) bool
- func (maps MapStrings) GetDefault(k, d string) string
- func (maps MapStrings) Implode(sep string) string
- func (maps MapStrings) Keys() []string
- func (maps MapStrings) Set(k, v string)
- func (maps MapStrings) SetForce(k, v string, force bool)
- func (maps MapStrings) ToJson() (string, error)
- func (maps MapStrings) ToUrlQuery(kSort bool) string
- func (maps MapStrings) Values() []string
- func (maps MapStrings) Verify(mustKey []string) MapStrings
- type Message
- func (m *Message) GetContent(gateway IGateway) string
- func (m *Message) GetData(gateway IGateway) MapStrings
- func (m *Message) GetGateways() []IGateway
- func (m *Message) GetMessageType() int
- func (m *Message) GetSignName(gateway IGateway) string
- func (m *Message) GetTemplate(gateway IGateway) string
- func (m Message) I() IMessage
- type MessageContentFun
- type MessageDataFun
- type MessageSignNameFun
- type MessageTemplateFun
- type PhoneNumber
- type SMSResult
- type SMSResults
Constants ¶
const StatusFailure = "failure"
const StatusSuccess = "success"
Variables ¶
var Client *requests.Client
Functions ¶
func ReplaceMapStrings ¶
func ReplaceMapStrings(s string, repl MapStrings) string
ReplaceMapStrings 您手机注册的验证码为:【变量1】,如有问题请拨打客服电话:【变量2】 new = MapStrings{"变量1":"111","变量2"::"222"} 您手机注册的验证码为:111,如有问题请拨打客服电话:222
func ReplaceMapStringsForStringIndex ¶
func ReplaceMapStringsForStringIndex(s, old string, news MapStrings) string
ReplaceMapStringsForStringIndex 您手机注册的验证码为:"您手机注册的验证码为:【变量】,如有问题请拨打客服电话:【变量】" new = MapStrings{"0": "111", "1": "222"} 您手机注册的验证码为:【111】,如有问题请拨打客服电话:【222】
func Sha256String ¶
Types ¶
type ClientResult ¶
type ClientResult struct {
// 状态值
Status string `json:"status" xml:"status"`
// 请求返回的数据
Response any `json:"response" xml:"response"`
// 错误返回的异常
Exception error `json:"exception" xml:"exception"`
}
ClientResult 网关响应结果的结构体
type GatewayMap ¶
type GoSMS ¶
type GoSMS struct {
//发送网关的别名
SendAsNames []string
// contains filtered or unexported fields
}
var (
SingletonGoSMS *GoSMS
)
func (*GoSMS) AddSendGateway ¶
AddSendGateway 直接注册发送网关
type IGateway ¶
type IGateway interface {
// I 用于初始化默认值
I() IGateway
// AsName 网关名称
AsName() string
// Send 发送操作
Send(to IPhoneNumber, message IMessage) (SMSResult, error)
}
IGateway 网关
type IMessage ¶
type IMessage interface {
I() IMessage
// GetMessageType 消息类型
GetMessageType() int
// GetSignName 签名
GetSignName(gateway IGateway) string
// GetContent 文字内容,使用在像云片类似的以文字内容发送的平台
GetContent(gateway IGateway) string
// GetTemplate 模板 ID,使用在以模板ID来发送短信的平台
GetTemplate(gateway IGateway) string
// GetData 模板变量,使用在以模板ID来发送短信的平台
GetData(gateway IGateway) MapStrings
// GetGateways 消息指定渠道发送
GetGateways() []IGateway
}
IMessage 消息内容
func MessageContent ¶
func MessageTemplate ¶
func MessageTemplate(template string, data MapStrings) IMessage
type IParser ¶
type IParser interface {
// FormatGateways 根据配置可以获取到对应到注册网关
FormatGateways() (gateways []IGateway)
}
IParser 配置信息解析器
type IPhoneNumber ¶
type IPhoneNumber interface {
I() IPhoneNumber
// GetCode 手机号号码前缀 例:中国 86
GetCode() int
// GetNumber 手机号 18888888888
GetNumber() int
// GetUniversalNumber 返回 +8618888888888
GetUniversalNumber() string
// GetZeroPrefixedNumber 返回 008618888888888
GetZeroPrefixedNumber() string
}
IPhoneNumber 手机号
type MapStringAny ¶
MapStringAny 二维以上map
func (MapStringAny) JsonUnmarshal ¶
func (maps MapStringAny) JsonUnmarshal(v any) error
JsonUnmarshal 解析json到实体上
func (MapStringAny) SetForce ¶
func (maps MapStringAny) SetForce(k string, v any, force bool)
SetForce Set 添加值 force=true 覆盖原值
func (MapStringAny) ToIMessage ¶
func (maps MapStringAny) ToIMessage() IMessage
ToIMessage 获取value 要设置默认值
func (MapStringAny) Verify ¶
func (maps MapStringAny) Verify(mustKey []string) MapStrings
Verify 验证出参数
type MapStrings ¶
MapStrings 一纬map
func (MapStrings) GetDefault ¶
func (maps MapStrings) GetDefault(k, d string) string
GetDefault 获取值并携带默认值
func (MapStrings) SetForce ¶
func (maps MapStrings) SetForce(k, v string, force bool)
SetForce Set 添加值 force=true 覆盖原值
func (MapStrings) ToUrlQuery ¶
func (maps MapStrings) ToUrlQuery(kSort bool) string
ToUrlQuery 转url请求参数
type Message ¶
type Message struct {
//消息类型
Type int `json:"type"`
//签名
SignName any `json:"sign_name"`
//消息内容
Content any `json:"content"`
//消息模版
Template any `json:"template"`
//消息模版数据
Data any `json:"data"`
//网关
Gateways []IGateway `json:"gateways"`
}
func (*Message) GetContent ¶
func (*Message) GetData ¶
func (m *Message) GetData(gateway IGateway) MapStrings
func (*Message) GetGateways ¶
func (*Message) GetMessageType ¶
func (*Message) GetSignName ¶
func (*Message) GetTemplate ¶
type MessageContentFun ¶
MessageContentFun 生成消息内容闭包
type MessageDataFun ¶
type MessageDataFun func(gateway IGateway) MapStrings
MessageDataFun 生成消息模版数据闭包
type MessageSignNameFun ¶
MessageSignNameFun 生成签名闭包
type MessageTemplateFun ¶
MessageTemplateFun 生成消息模版闭包
type PhoneNumber ¶
func (*PhoneNumber) GetCode ¶
func (p *PhoneNumber) GetCode() int
func (*PhoneNumber) GetNumber ¶
func (p *PhoneNumber) GetNumber() int
func (*PhoneNumber) GetUniversalNumber ¶
func (p *PhoneNumber) GetUniversalNumber() string
func (*PhoneNumber) GetZeroPrefixedNumber ¶
func (p *PhoneNumber) GetZeroPrefixedNumber() string
func (PhoneNumber) I ¶
func (p PhoneNumber) I() IPhoneNumber
type SMSResult ¶
type SMSResult struct {
Gateway IGateway `json:"gateway"`
PhoneNumber IPhoneNumber `json:"phone_number"`
Message IMessage `json:"message"`
ClientResult ClientResult `json:"client_result"`
}
SMSResult 网关统一的结构体
func BuildSMSResult ¶
func BuildSMSResult(phoneNumber IPhoneNumber, message IMessage, gateway IGateway, response any) SMSResult
BuildSMSResult 在网关快速生成结构体
type SMSResults ¶
type SMSResults []SMSResult
SMSResults 批量发
func SenderGateways ¶
func SenderGateways(number IPhoneNumber, message IMessage, gateways []IGateway) (smsResult SMSResults, err error)
SenderGateways 多渠道发送短信
func SenderNumbers ¶
func SenderNumbers(numbers []IPhoneNumber, message IMessage, gateway IGateway) (smsResult SMSResults, err error)
SenderNumbers 多手机号发送短信
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
_example
|
|
|
gosms
command
|
|
|
sender/ihuiyi
command
|
|
|
sender/juhe
command
|
|
|
sender/lmobile
command
|
|
|
sender/smsbao
command
|
|
|
sender/twilio
command
|
|
|
sender/yunxin
command
|
|