From 696db9307a206e62711df072ab2cfea692da4feb Mon Sep 17 00:00:00 2001 From: mhf Date: Mon, 13 Mar 2023 15:31:46 +0800 Subject: [PATCH] fix(notify): aliyunSmsdriver --- pkg/apis/notify/config.go | 30 +++++++++++++++------- pkg/notify/sender/mobile.go | 10 +++----- pkg/notify/sender/smsdriver/aliyun.go | 4 ++- pkg/notify/sender/smsdriver/huawei.go | 2 ++ pkg/notify/tasks/verification_send_task.go | 1 + 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/pkg/apis/notify/config.go b/pkg/apis/notify/config.go index bdcbd4a64d..0b2ddacd30 100644 --- a/pkg/apis/notify/config.go +++ b/pkg/apis/notify/config.go @@ -141,18 +141,30 @@ type SSendParams struct { } type SendParams struct { - Title string - Message string - Priority string - RemoteTemplate string - Topic string - Event string - Receivers SNotifyReceiver - EmailMsg *SEmailMessage - DomainId string + Title string + Message string + Priority string + RemoteTemplate string + Topic string + Event string + Receivers SNotifyReceiver + EmailMsg *SEmailMessage + DomainId string + RemoteTemplateParam SRemoteTemplateParam +} + +type SRemoteTemplateParam struct { + Code string `json:"code"` + Domain string `json:"domain"` + User string `json:"user"` + Type string `json:"type"` + AlertName string `json:"alert_name"` } type SSMSSendParams struct { + RemoteTemplate string + RemoteTemplateParam SRemoteTemplateParam + AppKey string AppSecret string From string diff --git a/pkg/notify/sender/mobile.go b/pkg/notify/sender/mobile.go index 0b82fcbc03..90bebfd7a2 100644 --- a/pkg/notify/sender/mobile.go +++ b/pkg/notify/sender/mobile.go @@ -15,8 +15,6 @@ package sender import ( - "strings" - "yunion.io/x/cloudmux/pkg/cloudprovider" "yunion.io/x/pkg/errors" @@ -35,10 +33,10 @@ func (smsSender *SMobileSender) GetSenderType() string { func (smsSender *SMobileSender) Send(args api.SendParams) error { smsSendParams := api.SSMSSendParams{ - TemplateId: strings.Split(args.RemoteTemplate, "/")[1], - TemplateParas: args.Message, - To: args.Receivers.Contact, - From: strings.Split(args.RemoteTemplate, "/")[0], + TemplateParas: args.Message, + To: args.Receivers.Contact, + RemoteTemplate: args.RemoteTemplate, + RemoteTemplateParam: args.RemoteTemplateParam, } smsdriver := models.GetSMSDriver(models.ConfigMap[api.MOBILE].Content.SmsDriver) return smsdriver.Send(smsSendParams, false, &api.NotifyConfig{ diff --git a/pkg/notify/sender/smsdriver/aliyun.go b/pkg/notify/sender/smsdriver/aliyun.go index 2bffe2a958..cd71b552f3 100644 --- a/pkg/notify/sender/smsdriver/aliyun.go +++ b/pkg/notify/sender/smsdriver/aliyun.go @@ -23,6 +23,7 @@ import ( "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" + "yunion.io/x/jsonutils" "yunion.io/x/pkg/errors" api "yunion.io/x/onecloud/pkg/apis/notify" @@ -55,6 +56,7 @@ func (d *SAliyunSMSDriver) Send(args api.SSMSSendParams, isVerify bool, config * args.AppSecret = models.ConfigMap[api.MOBILE].Content.AccessKeySecret args.Signature = models.ConfigMap[api.MOBILE].Content.Signature } + args.TemplateId = args.RemoteTemplate return d.sendSms(args) } @@ -84,7 +86,7 @@ func (d *SAliyunSMSDriver) sendSms(args api.SSMSSendParams) error { request.QueryParams["SignName"] = args.Signature request.QueryParams["TemplateCode"] = args.TemplateId - request.QueryParams["TemplateParam"] = args.TemplateParas + request.QueryParams["TemplateParam"] = jsonutils.Marshal(args.RemoteTemplateParam).String() return d.checkResponseAndError(client.ProcessCommonRequest(request)) } diff --git a/pkg/notify/sender/smsdriver/huawei.go b/pkg/notify/sender/smsdriver/huawei.go index 4493921c8d..e5d0f125c0 100644 --- a/pkg/notify/sender/smsdriver/huawei.go +++ b/pkg/notify/sender/smsdriver/huawei.go @@ -63,6 +63,8 @@ func (d *SHuaweiSMSDriver) Send(args api.SSMSSendParams, isVerify bool, config * args.Signature = models.ConfigMap[api.MOBILE].Content.Signature } + args.TemplateId = strings.Split(args.RemoteTemplate, "/")[1] + args.From = strings.Split(args.RemoteTemplate, "/")[0] return d.sendSms(args) } diff --git a/pkg/notify/tasks/verification_send_task.go b/pkg/notify/tasks/verification_send_task.go index e309c10b50..203497a673 100644 --- a/pkg/notify/tasks/verification_send_task.go +++ b/pkg/notify/tasks/verification_send_task.go @@ -106,6 +106,7 @@ func (self *VerificationSendTask) OnInit(ctx context.Context, obj db.IStandalone self.taskFailed(ctx, receiver, err.Error()) return } + param.RemoteTemplateParam = api.SRemoteTemplateParam{Code: verification.Token} param.Receivers = notifyReceiver param.EmailMsg = emailMsg driver := models.GetDriver(contactType)