代码拉取完成,页面将自动刷新
/*
* @Author: i@douxuefeng.cn
* @Date: 2022-04-09 21:28:45
* @LastEditTime: 2022-04-13 15:43:23
* @LastEditors: i@douxuefeng.cn
* @Description:
* @FilePath: \go-utils\sms\tencent_sms\qcloud.go
*/
package tencent_sms
import (
"encoding/json"
"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 tencentsms struct {
*Config
}
func NewTencentSms(cfg *Config) *tencentsms {
return &tencentsms{cfg}
}
func (s *tencentsms) Send(phone string, params []string) (string, error) {
credential := common.NewCredential(
s.SecretId,
s.SecretKey,
)
cpf := profile.NewClientProfile()
// cpf.Debug = true
client, _ := sms.NewClient(credential, "ap-guangzhou", cpf)
request := sms.NewSendSmsRequest()
request.SmsSdkAppId = common.StringPtr(s.SdkAppId)
request.SignName = common.StringPtr(s.Sign)
request.TemplateId = common.StringPtr(s.TemplateId)
request.TemplateParamSet = common.StringPtrs(params)
request.PhoneNumberSet = common.StringPtrs([]string{phone})
response, err := client.SendSms(request)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
return "", err
}
if err != nil {
return "", err
}
b, _ := json.Marshal(response.Response)
return string(b), nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。