1 Star 0 Fork 0

h79 / gothird

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sms.go 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2023-07-25 18:13 . 整理代码
package notify
import (
"fmt"
"gitee.com/h79/gothird/config"
"gitee.com/h79/goutils/common/result"
"math/rand"
"strings"
"time"
)
type SmsFillContentCallback func(interface{}) string
func SendSms(config *config.SmsConfig, phone string, content interface{}, call SmsFillContentCallback) (string, error) {
if config.IsEmpty() {
return "", result.Error(result.ErrSmsInternal, "config is empty")
}
txt := call(content)
if txt == "" {
return "", result.Error(result.ErrSmsInternal, "content is empty")
}
fmt.Println(txt)
if strings.EqualFold(config.Service, "aliyun") {
return SendAliyun(config, phone, txt)
} else if config.Service == "tencent" {
return SendTencentYun(config, phone, txt)
} else if config.Service == "qiniu" {
return SendQiNiuYun(config, phone, txt)
}
return "", result.RErrNotSupport
}
// GenSmsValidateCode
// 随机几位数字验证码生成
func GenSmsValidateCode(width int) string {
numeric := [10]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
r := len(numeric)
rand.Seed(time.Now().UnixNano())
var sb strings.Builder
for i := 0; i < width; i++ {
_, _ = fmt.Fprintf(&sb, "%d", numeric[rand.Intn(r)])
}
return sb.String()
}
1
https://gitee.com/h79/gothird.git
git@gitee.com:h79/gothird.git
h79
gothird
gothird
v1.8.101

搜索帮助