This commit is contained in:
Yun
2024-07-21 17:02:47 +08:00
parent 93512839d5
commit 3be60f7a73
2 changed files with 8 additions and 3 deletions
+4
View File
@@ -0,0 +1,4 @@
package aliyunx
// type
+4 -3
View File
@@ -1,8 +1,8 @@
package smsx
import (
"encoding/json"
"errors"
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi"
)
@@ -21,18 +21,19 @@ func NewSms(endPoint string, accessKeyId string, accessKeySecret string) *sms {
}
}
func (s *sms) Send(phone, code, signName, templateCode string) error {
func (s *sms) Send(phone, signName, templateCode string, params map[string]interface{}) error {
client, err := dysmsapi.NewClientWithAccessKey(s.endPoint, s.accessKeyId, s.accessKeySecret)
if err != nil {
return err
}
paramBy, _ := json.Marshal(params)
req := dysmsapi.CreateSendSmsRequest()
req.Scheme = "https"
req.PhoneNumbers = phone
req.SignName = signName
req.TemplateCode = templateCode
req.TemplateParam = fmt.Sprintf(`{"code":"%s"}`, code)
req.TemplateParam = string(paramBy)
resp, err := client.SendSms(req)
// fmt.Printf("sms send: resp:%+v err:%+v", resp, err)