1 Star 1 Fork 0

窦雪峰 / go-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
qcloud.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
窦雪峰 提交于 2022-04-13 15:43 . qcloud debug
/*
* @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
}
Go
1
https://gitee.com/douxuefeng/go-utils.git
git@gitee.com:douxuefeng/go-utils.git
douxuefeng
go-utils
go-utils
v0.2.6

搜索帮助