@@ -0,0 +1,61 @@
|
||||
package sms
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"91porn-server/common/sms/fengniao"
|
||||
"91porn-server/common/ysphone"
|
||||
)
|
||||
|
||||
type Provider = int
|
||||
|
||||
const (
|
||||
FengNiao Provider = 1 //蜂鸟
|
||||
YunPian Provider = 2 //云片
|
||||
)
|
||||
|
||||
type FengNiaoConfig struct {
|
||||
Url string `json:"url"`
|
||||
ChinaMercId string `json:"chinaMercId"`
|
||||
ChinaSecret string `json:"chinaSecret"`
|
||||
ChinaTmplId string `json:"chinaTmplId"`
|
||||
InterMercId string `json:"interMercId"`
|
||||
InterSecret string `json:"interSecret"`
|
||||
InterTmplId string `json:"interTmplId"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
FengNiao FengNiaoConfig `json:"fengNiao"`
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
|
||||
func Init(c Config) {
|
||||
cfg = c
|
||||
}
|
||||
|
||||
func sendByFengNiao(mobile string, code string) error {
|
||||
newMobile := ysphone.FormatPhoneNumber(mobile)
|
||||
fn := fengniao.FengNiao{
|
||||
Url: cfg.FengNiao.Url,
|
||||
MercId: cfg.FengNiao.InterMercId,
|
||||
Secret: cfg.FengNiao.InterSecret,
|
||||
Tmpl: cfg.FengNiao.InterTmplId,
|
||||
}
|
||||
if strings.HasPrefix(newMobile, "+86") {
|
||||
fn.MercId = cfg.FengNiao.ChinaMercId
|
||||
fn.Secret = cfg.FengNiao.ChinaSecret
|
||||
fn.Tmpl = cfg.FengNiao.ChinaTmplId
|
||||
}
|
||||
return (&fn).Send(newMobile, code)
|
||||
}
|
||||
|
||||
// Send 发送短信
|
||||
func Send(p Provider, mobile string, code string) error {
|
||||
switch p {
|
||||
case FengNiao:
|
||||
return sendByFengNiao(mobile, code)
|
||||
default:
|
||||
return sendByFengNiao(mobile, code)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user