42 lines
1008 B
Go
42 lines
1008 B
Go
|
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
|
||
|
}
|
||
|
|
||
|
func SendSms(request *dysmsapi.SendSmsRequest) (err error) {
|
||
|
_result, err := defaultDysmsapiClient.SendSms(request)
|
||
|
logger.Info("SendSms result:%v", _result)
|
||
|
if err != nil {
|
||
|
logger.Error("SendSms failed : %v", err)
|
||
|
}
|
||
|
return
|
||
|
}
|