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