sms.go 853 字节
package sms

const (
	SendSingle      SendType = 1
	SendList        SendType = 2
	SendSingleByTpl SendType = 10
)

const DefaultSmsCodeTimeOut int64 = 60 * 2

type (
	SendType    int
	ISmsService interface {
		Send(option *Options) error
	}
	Options struct {
		Phone     string
		Content   string
		SendType  SendType
		TplId     int
		TplValues map[string]interface{}
	}
	option func(o *Options)
)

func NewOptions(options ...option) *Options {
	o := &Options{}
	for i := range options {
		options[i](o)
	}
	return o
}
func WithPhone(phone string) option {
	return func(o *Options) {
		o.Phone = phone
	}
}
func WithSendType(sendType SendType) option {
	return func(o *Options) {
		o.SendType = sendType
	}
}
func WithTpl(tplId int, tplValues map[string]interface{}) option {
	return func(o *Options) {
		o.TplId = tplId
		o.TplValues = tplValues
	}
}