修改配置
This commit is contained in:
+22
-22
@@ -19,13 +19,13 @@ import (
|
||||
type Aliyun struct {
|
||||
interfaces.DefaultSmsx
|
||||
client *dysmsapi20170525.Client
|
||||
params entity.SmsConfigData
|
||||
params consts.SmsConfigData
|
||||
logger loggerx.LoggerInterface
|
||||
}
|
||||
|
||||
func (l *Aliyun) InitSmsx(ctx context.Context, params entity.SmsConfigData, logger loggerx.LoggerInterface) (interfaces.Smsx, error) {
|
||||
func (l *Aliyun) InitSmsx(ctx context.Context, params consts.SmsConfigData, logger loggerx.LoggerInterface) (interfaces.Smsx, error) {
|
||||
l.logger = logger
|
||||
if params.SysType != entity.Platform3rdTypeAliyun {
|
||||
if params.SysType != consts.Platform3rdTypeAliyun {
|
||||
return nil, errors.New("not aliyun")
|
||||
}
|
||||
|
||||
@@ -233,9 +233,9 @@ func (l *Aliyun) getTemp(ctx context.Context, page int32) ([]interfaces.Template
|
||||
for _, val := range resp.Body.SmsTemplateList {
|
||||
s := l.extractParams(tea.StringValue(val.TemplateContent))
|
||||
|
||||
params := []entity.SmsTemplateParam{}
|
||||
params := []consts.SmsTemplateParam{}
|
||||
for _, p := range s {
|
||||
params = append(params, entity.SmsTemplateParam{
|
||||
params = append(params, consts.SmsTemplateParam{
|
||||
FieldName: p,
|
||||
})
|
||||
}
|
||||
@@ -339,7 +339,7 @@ func (l *Aliyun) TempDel(ctx context.Context, templateId string) error {
|
||||
}
|
||||
|
||||
// 审核状态转换 短信平台=>本地
|
||||
func (l *Aliyun) auditStatusPlatToLocal(status string) entity.SmsTemplateStatus {
|
||||
func (l *Aliyun) auditStatusPlatToLocal(status string) consts.SmsTemplateStatus {
|
||||
|
||||
// AUDIT_STATE_INIT:审核中。
|
||||
// AUDIT_STATE_PASS:通过审核。
|
||||
@@ -349,21 +349,21 @@ func (l *Aliyun) auditStatusPlatToLocal(status string) entity.SmsTemplateStatus
|
||||
|
||||
switch status {
|
||||
case "AUDIT_STATE_INIT":
|
||||
return entity.SmsTemplateStatusAudit
|
||||
return consts.SmsTemplateStatusAudit
|
||||
case "AUDIT_STATE_PASS":
|
||||
return entity.SmsTemplateStatusPass
|
||||
return consts.SmsTemplateStatusPass
|
||||
case "AUDIT_STATE_NOT_PASS":
|
||||
return entity.SmsTemplateStatusUnPass
|
||||
return consts.SmsTemplateStatusUnPass
|
||||
case "AUDIT_STATE_CANCEL":
|
||||
return entity.SmsTemplateStatusCancel
|
||||
return consts.SmsTemplateStatusCancel
|
||||
case "AUDIT_SATE_CANCEL":
|
||||
return entity.SmsTemplateStatusCancel
|
||||
return consts.SmsTemplateStatusCancel
|
||||
default:
|
||||
return entity.SmsTemplateStatusUnknown
|
||||
return consts.SmsTemplateStatusUnknown
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Aliyun) tempTypePlatToLocal(platType int32) entity.SmsTemplateType {
|
||||
func (l *Aliyun) tempTypePlatToLocal(platType int32) consts.SmsTemplateType {
|
||||
// 0:验证码短信。
|
||||
// 1:通知短信。
|
||||
// 2:推广短信。
|
||||
@@ -372,26 +372,26 @@ func (l *Aliyun) tempTypePlatToLocal(platType int32) entity.SmsTemplateType {
|
||||
|
||||
switch platType {
|
||||
case 0:
|
||||
return entity.SmsTemplateTypeVerifyCode
|
||||
return consts.SmsTemplateTypeVerifyCode
|
||||
case 1:
|
||||
return entity.SmsTemplateTypeNotice
|
||||
return consts.SmsTemplateTypeNotice
|
||||
case 2:
|
||||
return entity.SmsTemplateTypePromotion
|
||||
return consts.SmsTemplateTypePromotion
|
||||
case 3:
|
||||
return entity.SmsTemplateTypeInternational
|
||||
return consts.SmsTemplateTypeInternational
|
||||
case 7:
|
||||
return entity.SmsTemplateTypeDigital
|
||||
return consts.SmsTemplateTypeDigital
|
||||
default:
|
||||
return entity.SmsTemplateTypeUnknown
|
||||
return consts.SmsTemplateTypeUnknown
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Aliyun) tempRangePlatToLocal(platType int32) entity.SmsTemplateRange {
|
||||
func (l *Aliyun) tempRangePlatToLocal(platType int32) consts.SmsTemplateRange {
|
||||
// 非国际/港澳台短信。
|
||||
if platType == 3 {
|
||||
return entity.SmsTemplateRangeInternational
|
||||
return consts.SmsTemplateRangeInternational
|
||||
}
|
||||
return entity.SmsTemplateRangeChina
|
||||
return consts.SmsTemplateRangeChina
|
||||
}
|
||||
|
||||
// 提取参数
|
||||
|
||||
@@ -16,9 +16,9 @@ func TestSend(t *testing.T) {
|
||||
|
||||
logger := loggerx.NewLogger(ctx)
|
||||
|
||||
params := entity.SmsConfigData{
|
||||
SysType: entity.Platform3rdTypeAliyun,
|
||||
Aliyun: &entity.SmsConfigDataAliyun{
|
||||
params := consts.SmsConfigData{
|
||||
SysType: consts.Platform3rdTypeAliyun,
|
||||
Aliyun: &consts.SmsConfigDataAliyun{
|
||||
AccessKeyId: "LTAI5tSgopmbntKXnq8ESrvh",
|
||||
AccessKeySecret: "BEgEFCOh4eokzhg8EfxeETbSk4B2UJ",
|
||||
SignName: "深圳展鸣科技",
|
||||
@@ -46,9 +46,9 @@ func TestGetTemp(t *testing.T) {
|
||||
|
||||
logger := loggerx.NewLogger(ctx)
|
||||
|
||||
params := entity.SmsConfigData{
|
||||
SysType: entity.Platform3rdTypeAliyun,
|
||||
Aliyun: &entity.SmsConfigDataAliyun{
|
||||
params := consts.SmsConfigData{
|
||||
SysType: consts.Platform3rdTypeAliyun,
|
||||
Aliyun: &consts.SmsConfigDataAliyun{
|
||||
AccessKeyId: "LTAI5tSgopmbntKXnq8ESrvh",
|
||||
AccessKeySecret: "BEgEFCOh4eokzhg8EfxeETbSk4B2UJ",
|
||||
SignName: "深圳展鸣科技",
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package entity
|
||||
package consts
|
||||
|
||||
// 第三方平台
|
||||
type Platform3rdType string
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package entity
|
||||
package consts
|
||||
|
||||
type SmsConfig struct {
|
||||
SmsType Platform3rdType `json:"sms_type" gorm:"column:sms_type;not null;comment:短信类型(ali.阿里云 tencent.腾讯云 smsbao.短信宝)"`
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package entity
|
||||
package consts
|
||||
|
||||
|
||||
type SmsTemplate struct {
|
||||
|
||||
+4
-4
@@ -14,15 +14,15 @@ func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
logger := loggerx.NewLogger(ctx)
|
||||
sms, err := smsx.GetPlatform(ctx, entity.Platform3rdTypeTencent)
|
||||
sms, err := smsx.GetPlatform(ctx, consts.Platform3rdTypeTencent)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
ini, err := sms.InitSmsx(ctx, entity.SmsConfigData{
|
||||
SysType: entity.Platform3rdTypeTencent,
|
||||
Tencent: &entity.SmsConfigDataTencent{
|
||||
ini, err := sms.InitSmsx(ctx, consts.SmsConfigData{
|
||||
SysType: consts.Platform3rdTypeTencent,
|
||||
Tencent: &consts.SmsConfigDataTencent{
|
||||
SecretId: "AKIDb2b8SefT8YjgUBk8N0XtANMSZWFqLiIp",
|
||||
SecretKey: "QxqstqipqkTzfKqGVdgr3Merx0uvoU3R",
|
||||
SignName: "深圳宏建源贸易",
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type Smsx interface {
|
||||
InitSmsx(ctx context.Context, params entity.SmsConfigData,logger loggerx.LoggerInterface) (Smsx, error)
|
||||
InitSmsx(ctx context.Context, params consts.SmsConfigData,logger loggerx.LoggerInterface) (Smsx, error)
|
||||
// Send 发送短信
|
||||
// templateId: 短信模板ID
|
||||
// phone: 手机号(格式:+86xxx)
|
||||
@@ -31,17 +31,17 @@ type SmsSendParam struct {
|
||||
type TemplateInfo struct {
|
||||
TempId string `json:"temp_id"` // 模板ID
|
||||
TempName string `json:"temp_name"` // 模板名称
|
||||
TempType entity.SmsTemplateType `json:"temp_type"` // 模板类型
|
||||
TempRange entity.SmsTemplateRange `json:"temp_range"` // 作用范围
|
||||
TempType consts.SmsTemplateType `json:"temp_type"` // 模板类型
|
||||
TempRange consts.SmsTemplateRange `json:"temp_range"` // 作用范围
|
||||
Content string `json:"content"` // 内容
|
||||
Status entity.SmsTemplateStatus `json:"status"` // 状态 (1.通过审核 2.审核中 3.未通过审核 4.取消审核)
|
||||
Params []entity.SmsTemplateParam `json:"params"` // 模板参数
|
||||
Status consts.SmsTemplateStatus `json:"status"` // 状态 (1.通过审核 2.审核中 3.未通过审核 4.取消审核)
|
||||
Params []consts.SmsTemplateParam `json:"params"` // 模板参数
|
||||
}
|
||||
|
||||
// 默认的实现
|
||||
type DefaultSmsx struct{}
|
||||
|
||||
func (l *DefaultSmsx) InitSmsx(ctx context.Context, params entity.SmsConfigData,logger loggerx.LoggerInterface) (Smsx, error) {
|
||||
func (l *DefaultSmsx) InitSmsx(ctx context.Context, params consts.SmsConfigData,logger loggerx.LoggerInterface) (Smsx, error) {
|
||||
return &DefaultSmsx{}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -10,18 +10,18 @@ import (
|
||||
"code.yun.ink/pkg/smsx/tencent"
|
||||
)
|
||||
|
||||
var platform map[entity.Platform3rdType]interfaces.Smsx
|
||||
var platform map[consts.Platform3rdType]interfaces.Smsx
|
||||
|
||||
// 注册
|
||||
func init() {
|
||||
platform = make(map[entity.Platform3rdType]interfaces.Smsx)
|
||||
platform = make(map[consts.Platform3rdType]interfaces.Smsx)
|
||||
// 阿里
|
||||
platform[entity.Platform3rdTypeAliyun] = &aliyun.Aliyun{}
|
||||
platform[consts.Platform3rdTypeAliyun] = &aliyun.Aliyun{}
|
||||
// 腾讯
|
||||
platform[entity.Platform3rdTypeTencent] = &tencent.Tencent{}
|
||||
platform[consts.Platform3rdTypeTencent] = &tencent.Tencent{}
|
||||
}
|
||||
|
||||
func GetPlatform(ctx context.Context, plat entity.Platform3rdType) (interfaces.Smsx, error) {
|
||||
func GetPlatform(ctx context.Context, plat consts.Platform3rdType) (interfaces.Smsx, error) {
|
||||
iplat, ok := platform[plat]
|
||||
if ok {
|
||||
return iplat, nil
|
||||
|
||||
+18
-18
@@ -18,13 +18,13 @@ import (
|
||||
type Tencent struct {
|
||||
interfaces.DefaultSmsx
|
||||
client *sms.Client
|
||||
params entity.SmsConfigData
|
||||
params consts.SmsConfigData
|
||||
logger loggerx.LoggerInterface
|
||||
}
|
||||
|
||||
func (l *Tencent) InitSmsx(ctx context.Context, params entity.SmsConfigData, logger loggerx.LoggerInterface) (interfaces.Smsx, error) {
|
||||
func (l *Tencent) InitSmsx(ctx context.Context, params consts.SmsConfigData, logger loggerx.LoggerInterface) (interfaces.Smsx, error) {
|
||||
l.logger = logger
|
||||
if params.SysType != entity.Platform3rdTypeTencent || params.Tencent == nil {
|
||||
if params.SysType != consts.Platform3rdTypeTencent || params.Tencent == nil {
|
||||
return nil, errors.New("not tencent")
|
||||
}
|
||||
|
||||
@@ -289,10 +289,10 @@ func (l *Tencent) getTemp(ctx context.Context, page uint64, internal uint64) ([]
|
||||
if val.TemplateContent != nil {
|
||||
info.Content = *val.TemplateContent
|
||||
|
||||
p := []entity.SmsTemplateParam{}
|
||||
p := []consts.SmsTemplateParam{}
|
||||
s := l.extractParams(*val.TemplateContent)
|
||||
for _, v := range s {
|
||||
p = append(p, entity.SmsTemplateParam{
|
||||
p = append(p, consts.SmsTemplateParam{
|
||||
FieldName: v,
|
||||
})
|
||||
}
|
||||
@@ -325,41 +325,41 @@ func (l *Tencent) TempDel(ctx context.Context, templateId string) error {
|
||||
}
|
||||
|
||||
// 判断作用范围
|
||||
func (l *Tencent) tempRangePlatToLocal(plat uint64) entity.SmsTemplateRange {
|
||||
func (l *Tencent) tempRangePlatToLocal(plat uint64) consts.SmsTemplateRange {
|
||||
// 是否国际/港澳台短信,其中0表示国内短信,1表示国际/港澳台短信,3表示该模板既支持国内短信也支持国际/港澳台短信。
|
||||
switch plat {
|
||||
case 0:
|
||||
return entity.SmsTemplateRangeChina
|
||||
return consts.SmsTemplateRangeChina
|
||||
case 1:
|
||||
return entity.SmsTemplateRangeInternational
|
||||
return consts.SmsTemplateRangeInternational
|
||||
case 3:
|
||||
return entity.SmsTemplateRangeGlobal
|
||||
return consts.SmsTemplateRangeGlobal
|
||||
default:
|
||||
return entity.SmsTemplateRangeChina // 若未找到匹配项,默认为国内短信
|
||||
return consts.SmsTemplateRangeChina // 若未找到匹配项,默认为国内短信
|
||||
}
|
||||
}
|
||||
|
||||
// 审核状态转换
|
||||
func (l *Tencent) auditStatusPlatToLocal(plat int64) entity.SmsTemplateStatus {
|
||||
func (l *Tencent) auditStatusPlatToLocal(plat int64) consts.SmsTemplateStatus {
|
||||
// 申请模板状态,其中0表示审核通过且已生效,1表示审核中,2表示审核通过待生效,-1表示审核未通过或审核失败。注:只有状态值为0时该模板才能使用。
|
||||
switch plat {
|
||||
case 0:
|
||||
return entity.SmsTemplateStatusPass
|
||||
return consts.SmsTemplateStatusPass
|
||||
case 1:
|
||||
return entity.SmsTemplateStatusAudit
|
||||
return consts.SmsTemplateStatusAudit
|
||||
case 2:
|
||||
return entity.SmsTemplateStatusAudit
|
||||
return consts.SmsTemplateStatusAudit
|
||||
case -1:
|
||||
return entity.SmsTemplateStatusUnPass
|
||||
return consts.SmsTemplateStatusUnPass
|
||||
default:
|
||||
return entity.SmsTemplateStatusUnPass // 若未找到匹配项,默认为审核未通过或审核失败
|
||||
return consts.SmsTemplateStatusUnPass // 若未找到匹配项,默认为审核未通过或审核失败
|
||||
}
|
||||
}
|
||||
|
||||
// 模板类型转换(查询接口没返回)
|
||||
func (l *Tencent) tempTypePlatToLocal(plat uint64) entity.SmsTemplateType {
|
||||
func (l *Tencent) tempTypePlatToLocal(plat uint64) consts.SmsTemplateType {
|
||||
// 是否国际/港澳台短信,其中0表示国内短信,1表示国际/港澳台短信,3表示该模板既支持国内短信也支持国际/港澳台短信。
|
||||
return entity.SmsTemplateTypeUnknown
|
||||
return consts.SmsTemplateTypeUnknown
|
||||
}
|
||||
|
||||
// 提取参数
|
||||
|
||||
@@ -29,9 +29,9 @@ func TestGetTemp(t *testing.T) {
|
||||
|
||||
ten := tencent.Tencent{}
|
||||
|
||||
ini, err := ten.InitSmsx(ctx, entity.SmsConfigData{
|
||||
SysType: entity.Platform3rdTypeTencent,
|
||||
Tencent: &entity.SmsConfigDataTencent{
|
||||
ini, err := ten.InitSmsx(ctx, consts.SmsConfigData{
|
||||
SysType: consts.Platform3rdTypeTencent,
|
||||
Tencent: &consts.SmsConfigDataTencent{
|
||||
SecretId: "AKIDb2b8SefT8YjgUBk8N0XtANMSZWFqLiIp",
|
||||
SecretKey: "QxqstqipqkTzfKqGVdgr3Merx0uvoU3R",
|
||||
SignName: "深圳宏建源贸易",
|
||||
@@ -69,9 +69,9 @@ func TestSend(t *testing.T) {
|
||||
// SmsSdkAppId: "1400932084",
|
||||
// },
|
||||
|
||||
ini, err := ten.InitSmsx(ctx, entity.SmsConfigData{
|
||||
SysType: entity.Platform3rdTypeTencent,
|
||||
Tencent: &entity.SmsConfigDataTencent{
|
||||
ini, err := ten.InitSmsx(ctx, consts.SmsConfigData{
|
||||
SysType: consts.Platform3rdTypeTencent,
|
||||
Tencent: &consts.SmsConfigDataTencent{
|
||||
SecretId: "AKIDb2b8SefT8YjgUBk8N0XtANMSZWFqLiIp",
|
||||
SecretKey: "QxqstqipqkTzfKqGVdgr3Merx0uvoU3R",
|
||||
SignName: "深圳宏建源贸易",
|
||||
|
||||
Reference in New Issue
Block a user