package sms import ( "fmt" "log" "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" ) type Tencent struct { SignName string AppId string AppKey string TemplateId string } func (c *Tencent) Send(datatype, dataparams, phones interface{}) (interface{}, error) { credential := common.NewCredential( "AKIDKTMzLQErDJ8gxwe5F8j36sMZWCbjaBUW", "mHVR6UbRzGGzRbU6RUGlzwc2A1astgIi", ) cpf := profile.NewClientProfile() cpf.HttpProfile.Endpoint = "sms.tencentcloudapi.com" client, _ := sms.NewClient(credential, "ap-nanjing", cpf) request := sms.NewSendSmsRequest() request.PhoneNumberSet = common.StringPtrs(phones.([]string)) request.SmsSdkAppId = common.StringPtr(c.AppId) request.SignName = common.StringPtr(c.SignName) request.TemplateId = common.StringPtr(c.TemplateId) request.TemplateParamSet = common.StringPtrs(dataparams.([]string)) response, err := client.SendSms(request) if _, ok := err.(*errors.TencentCloudSDKError); ok { errid := *request.SenderId return nil, errors.NewTencentCloudSDKError("", fmt.Sprintf("An API error has returned: %s", err), errid) } if err != nil { log.Println(err) return nil, err } //fmt.Printf("%s", response.ToJsonString()) return response, nil }