2023-12-21 22:17:40 +08:00
|
|
|
package sms
|
|
|
|
|
|
|
|
import (
|
|
|
|
"service/bizcommon/util"
|
|
|
|
"service/library/configcenter"
|
|
|
|
"service/library/logger"
|
|
|
|
|
|
|
|
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
|
|
|
dysmsapi "github.com/alibabacloud-go/dysmsapi-20170525/v3/client"
|
|
|
|
"github.com/alibabacloud-go/tea/tea"
|
|
|
|
)
|
|
|
|
|
|
|
|
var defaultDysmsapiClient *dysmsapi.Client
|
|
|
|
|
|
|
|
func Init(cfg *configcenter.DysmsapiConfig) (err error) {
|
|
|
|
|
|
|
|
config := &openapi.Config{
|
|
|
|
AccessKeyId: tea.String(cfg.AccessKeyId),
|
|
|
|
AccessKeySecret: tea.String(cfg.AccessKeySecret),
|
|
|
|
}
|
|
|
|
// 访问的域名
|
|
|
|
config.Endpoint = tea.String("dysmsapi.aliyuncs.com")
|
|
|
|
|
|
|
|
defaultDysmsapiClient, err = dysmsapi.NewClient(config)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("NewDysmsapiClient fail, cfg: %v, err: %v", util.ToJson(config), err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-08-07 14:22:08 +08:00
|
|
|
func SendSms(request *dysmsapi.SendSmsRequest) (_result *dysmsapi.SendSmsResponse, err error) {
|
|
|
|
_result, err = defaultDysmsapiClient.SendSms(request)
|
2023-12-21 22:17:40 +08:00
|
|
|
logger.Info("SendSms result:%v", _result)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("SendSms failed : %v", err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|