Files
2026-05-20 16:13:58 +08:00

59 lines
1.5 KiB
Go

package sms
import (
"stat/common/sms/fengniao"
"stat/common/sms/yunpian"
"stat/common/ysphone"
"strings"
)
type Provider = int
const (
tmplChinaId = "5ecfc70ab6a62a37c00baf74" //大陆模版
interNationId = "5ecfbfc3b6a62a37c00ba945" //国际模版
chinaTmpl = "【PFYH】您的验证码是:%s。请不要把验证码泄露给其他人。"
interTmpl = "[YueHui] Your verification code is: %s Please do not disclose the verification code to others."
tmplYunPian = "【泡芙官网】您的验证码是:%s。请不要把验证码泄漏给其他人。"
)
const (
FengNiao Provider = 1 //蜂鸟
YunPian Provider = 2 //云片
)
func sendByFengNiao(mobile string, code string) error {
newMobile := ysphone.FormatPhoneNumber(mobile)
var tmplId string
if strings.HasPrefix(newMobile, "+86") {
tmplId = tmplChinaId
} else {
tmplId = interNationId
}
return (&fengniao.FengNiao{
Url: "https://rise.sudukj.com/api/sms/sendSms",
MercId: "10103",
Secret: "a7934623f508122fab27373fdee0e410",
Tmpl: tmplId,
}).Send(newMobile, code)
}
func sendByYunPian(mobile string, code string) error {
return (&yunpian.YunPian{
Apikey: "a2c52f92f570d839e203ce0c41eb4bc5",
Tmpl: tmplYunPian,
}).Send(mobile, code)
}
// Send 发送短信
func Send(p Provider, mobile string, code string) error {
switch p {
case FengNiao:
return sendByFengNiao(mobile, code)
case YunPian:
return sendByYunPian(mobile, code)
default:
return sendByFengNiao(mobile, code)
}
}