diff --git a/pkg/apis/notify/config.go b/pkg/apis/notify/config.go index 63aaadbc8e..764bbcef4a 100644 --- a/pkg/apis/notify/config.go +++ b/pkg/apis/notify/config.go @@ -226,6 +226,10 @@ type SNotifyConfigContent struct { //AppSecret string AppKey string // sms + VerifiyCode string + AlertsCode string + ErrorCode string + PhoneNumber string AccessKeyId string AccessKeySecret string ServiceUrl string diff --git a/pkg/notify/sender/smsdriver/aliyun.go b/pkg/notify/sender/smsdriver/aliyun.go index cd71b552f3..e994120d94 100644 --- a/pkg/notify/sender/smsdriver/aliyun.go +++ b/pkg/notify/sender/smsdriver/aliyun.go @@ -39,11 +39,11 @@ func (d *SAliyunSMSDriver) Name() string { } func (d *SAliyunSMSDriver) Verify(config *api.NotifyConfig) error { - err := d.Send(api.SSMSSendParams{}, true, config) - if err == ErrSignnameInvalid || err == ErrSignatureDoesNotMatch || err == ErrAccessKeyIdNotFound { - return nil - } - return errors.Wrap(err, "Verify") + return d.Send(api.SSMSSendParams{ + RemoteTemplate: config.VerifiyCode, + To: config.PhoneNumber, + RemoteTemplateParam: api.SRemoteTemplateParam{Code: "0000"}, + }, true, config) } func (d *SAliyunSMSDriver) Send(args api.SSMSSendParams, isVerify bool, config *api.NotifyConfig) error { @@ -64,9 +64,8 @@ func (d *SAliyunSMSDriver) sendSms(args api.SSMSSendParams) error { // lock and update client, err := sdk.NewClientWithAccessKey("default", args.AppKey, args.AppSecret) if err != nil { - return err + return errors.Wrap(err, "NewClientWithAccessKey") } - m := parser.FindStringSubmatch(args.To) if len(m) > 0 { if m[1] == "86" { diff --git a/pkg/notify/sender/smsdriver/huawei.go b/pkg/notify/sender/smsdriver/huawei.go index e5d0f125c0..99334558a0 100644 --- a/pkg/notify/sender/smsdriver/huawei.go +++ b/pkg/notify/sender/smsdriver/huawei.go @@ -45,11 +45,11 @@ func (d *SHuaweiSMSDriver) Name() string { } func (d *SHuaweiSMSDriver) Verify(config *api.NotifyConfig) error { - err := d.Send(api.SSMSSendParams{}, true, config) - if err == ErrSignnameInvalid || err == ErrSignatureDoesNotMatch || err == ErrAccessKeyIdNotFound { - return nil - } - return errors.Wrap(err, "Verify") + return d.Send(api.SSMSSendParams{ + RemoteTemplate: config.VerifiyCode, + To: config.PhoneNumber, + RemoteTemplateParam: api.SRemoteTemplateParam{Code: "0000"}, + }, true, config) } func (d *SHuaweiSMSDriver) Send(args api.SSMSSendParams, isVerify bool, config *api.NotifyConfig) error { @@ -62,7 +62,6 @@ func (d *SHuaweiSMSDriver) 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 = strings.Split(args.RemoteTemplate, "/")[1] args.From = strings.Split(args.RemoteTemplate, "/")[0] return d.sendSms(args)