package sms import ( "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" ) /** * 使用腾讯云发送短信 * @secretId 腾讯云密钥id * @secretKey 腾讯云密钥key * @signname 签名 * @templateId 模板id * @params 参数值 */ func SendByTencent(secretId, secretKey, smsAppId string, signname string, mobiles []string, templateId string, params []string) (*string, []*sms.SendStatus, error) { credential := common.NewCredential( secretId, secretKey, ) cpf := profile.NewClientProfile() cpf.HttpProfile.Endpoint = "sms.tencentcloudapi.com" client, _ := sms.NewClient(credential, "ap-guangzhou", cpf) request := sms.NewSendSmsRequest() request.PhoneNumberSet = common.StringPtrs(mobiles) //[]string{"18607552321"} request.SmsSdkAppId = common.StringPtr(smsAppId) request.SignName = common.StringPtr(signname) request.TemplateId = common.StringPtr(templateId) request.TemplateParamSet = common.StringPtrs(params) //[]string{"param1", "param2"} response, err := client.SendSms(request) if _, ok := err.(*errors.TencentCloudSDKError); ok { log.Println("An API error has returned: ", err) return nil, nil, err } if err != nil { log.Println(err) return nil, nil, err } return response.Response.RequestId, response.Response.SendStatusSet, nil }