123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- package notify
- import (
- "encoding/json"
- errors2 "errors"
- "iot_manager_service/config"
- "strings"
- "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
- "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
- "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
- sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111"
- )
- func SendTencentSms(receiverPhoneNumbers []string, smsTemplateId string, values []string) error {
- mainConfig := config.Instance().MonitNotice.Sms.Tencent
-
- credential := common.NewCredential(
- mainConfig.SecretID,
- mainConfig.SecretKey,
- )
-
- cpf := profile.NewClientProfile()
-
- cpf.HttpProfile.ReqMethod = "POST"
-
-
-
- cpf.HttpProfile.Endpoint = "sms.tencentcloudapi.com"
-
- cpf.SignMethod = "HmacSHA1"
-
- client, _ := sms.NewClient(credential, "ap-guangzhou", cpf)
-
- request := sms.NewSendSmsRequest()
-
-
-
- request.SmsSdkAppId = common.StringPtr(mainConfig.AppID)
-
-
- request.SignName = common.StringPtr(mainConfig.SmsKey)
-
-
- request.TemplateId = common.StringPtr(smsTemplateId)
-
- request.TemplateParamSet = common.StringPtrs(values)
-
- request.PhoneNumberSet = common.StringPtrs(receiverPhoneNumbers)
-
- request.SessionContext = common.StringPtr("")
-
- request.ExtendCode = common.StringPtr("")
-
- request.SenderId = common.StringPtr("")
-
- response, err := client.SendSms(request)
-
- if _, ok := err.(*errors.TencentCloudSDKError); ok {
- return err
- }
-
- if err != nil {
- return err
- }
- b, _ := json.Marshal(response.Response)
-
-
-
-
-
-
- if !strings.Contains(string(b), "OK") {
- return errors2.New(string(b))
- }
-
- return nil
-
- }
|