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 参数值
|
|
* @region 区域, ap-guangzhou|ap-beijing|ap-shanghai
|
|
|
|
* @return *requestId,[]*sendStatus,error
|
|
*
|
|
*/
|
|
func SendByTencent(secretId, secretKey, smsAppId string, signname string, mobiles []string, templateId string, params []string, region ...string) (*string, []*sms.SendStatus, error) {
|
|
|
|
credential := common.NewCredential(
|
|
secretId,
|
|
secretKey,
|
|
)
|
|
cpf := profile.NewClientProfile()
|
|
cpf.HttpProfile.Endpoint = "sms.tencentcloudapi.com"
|
|
|
|
region_default := "ap-guangzhou"
|
|
if len(region) > 0 {
|
|
region_default = region[0]
|
|
}
|
|
client, _ := sms.NewClient(credential, region_default, 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
|
|
|
|
}
|