package global import ( "fmt" "github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi" "goweb/config" ) type aliSmsBot struct{} // SentSms 发送短信验证码 func (b aliSmsBot) SentSms(phone string, code string) bool { client, err := dysmsapi.NewClientWithAccessKey("ap-northeast-1", config.AliSmsConfig.AccessKey, config.AliSmsConfig.AccessSecret) request := dysmsapi.CreateSendSmsRequest() request.Scheme = "https" request.PhoneNumbers = phone request.SignName = "悟空单车" request.TemplateCode = "SMS_34310120" request.TemplateParam = fmt.Sprintf("{\"name\":\"%v\",\"code\":\"%v\"}", phone, code) response, err := client.SendSms(request) if err != nil { Log.Errorf("验证码发送失败: %v", err.Error()) return false } return response.IsSuccess() }