1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package sms
- import (
- "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/v20190711"
- "zhiyuan/pkg/config"
- )
- var client *sms.Client
- func Setup() {
- credential := common.NewCredential(
- config.Cfg.Sms.AccessKey,
- config.Cfg.Sms.AccessSecret,
- )
- client, _ = sms.NewClient(credential, "ap-guangzhou", profile.NewClientProfile())
- }
- func SendSms(phone []string, signName string, templateCode string, templeteParam []string) error {
- request := sms.NewSendSmsRequest()
- request.SmsSdkAppid = common.StringPtr(config.Cfg.Sms.AppID)
- request.Sign = common.StringPtr(signName)
- if templateCode != "" {
- request.TemplateID = common.StringPtr(templateCode)
- }
- if templeteParam != nil {
- request.TemplateParamSet = common.StringPtrs(templeteParam)
- }
- request.PhoneNumberSet = common.StringPtrs(phone)
- _, err := client.SendSms(request)
- if _, ok := err.(*errors.TencentCloudSDKError); ok {
- return err
- }
- if err != nil {
- return err
- }
- //fmt.Println(response.Response)
- return nil
- }
|