...
|
...
|
@@ -5,7 +5,13 @@ import ( |
|
|
"fmt"
|
|
|
)
|
|
|
|
|
|
var yunPianSmsTpl = map[string]SmsTpl{
|
|
|
type ISmsTpl interface {
|
|
|
ParseTpl(v ...interface{}) (string, error)
|
|
|
String() string
|
|
|
}
|
|
|
|
|
|
//注册短信模板
|
|
|
var smsTpl = map[string]ISmsTpl{
|
|
|
"10001": SmsTpl{"【云片网】您的验证码是%s", 1},
|
|
|
}
|
|
|
|
...
|
...
|
@@ -14,11 +20,6 @@ const ( |
|
|
TplFormateErr string = "tpl formate error"
|
|
|
)
|
|
|
|
|
|
type ISmsTpl interface {
|
|
|
ParseTpl(v ...interface{}) (string, error)
|
|
|
String() string
|
|
|
}
|
|
|
|
|
|
type SmsTpl struct {
|
|
|
Formate string
|
|
|
ParamNum int
|
...
|
...
|
@@ -28,6 +29,7 @@ var ( |
|
|
_ ISmsTpl = SmsTpl{}
|
|
|
)
|
|
|
|
|
|
//ParseTpl 根据传参填充模板内容
|
|
|
func (t SmsTpl) ParseTpl(v ...interface{}) (string, error) {
|
|
|
if len(v) < t.ParamNum {
|
|
|
return "", errors.New(TplFormateErr)
|
...
|
...
|
@@ -35,12 +37,15 @@ func (t SmsTpl) ParseTpl(v ...interface{}) (string, error) { |
|
|
return fmt.Sprintf(t.String(), v), nil
|
|
|
}
|
|
|
|
|
|
//String 返回模板字符串
|
|
|
func (t SmsTpl) String() string {
|
|
|
return t.Formate
|
|
|
}
|
|
|
|
|
|
//getSmsTpl 获取样板
|
|
|
//TODO 待优化
|
|
|
func getSmsTpl(code string) (ISmsTpl, error) {
|
|
|
if tpl, ok := yunPianSmsTpl[code]; ok {
|
|
|
if tpl, ok := smsTpl[code]; ok {
|
|
|
return tpl, nil
|
|
|
}
|
|
|
return nil, errors.New(TplNotExit)
|
...
|
...
|
|