package sms import ( "errors" "git.tetele.net/tgo/helper" dysmsapi "github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi" "log" ) /** * 阿里云短信 * @accessKeyId 用来验证用户身份的keyId * @accessKeySecret 用来验证用户身份的secret * @signName 短信签名名称 * @templateCode 短信模板CODE * @phoneNumbers 手机号,多个用逗号隔开 * @teplateParam 短信内容 */ func SendByALiYun(accessKeyId string, accessKeySecret string, phoneNumbers string, signName string, templateCode string, teplateParam string) (bool, error) { if accessKeyId == "" || accessKeySecret == "" || phoneNumbers == "" || signName == "" || templateCode == "" || teplateParam == "" { return false, errors.New("参数不全") } client, err := dysmsapi.NewClientWithAccessKey("cn-qingdao", accessKeyId, accessKeySecret) /* use STS Token client, err := dysmsapi.NewClientWithStsToken("cn-qingdao", "", "", "") */ request := dysmsapi.CreateSendSmsRequest() request.Scheme = "https" request.PhoneNumbers = phoneNumbers // 接收短信的手机号码 request.SignName = signName // 短信签名名称 request.TemplateCode = templateCode // 短信模板ID request.TemplateParam = teplateParam response, err := client.SendSms(request) if err != nil { log.Println("post err", err) return false, err } // var reply_data map[string]interface{} // err = json.Unmarshal(response, &reply_data) // if err != nil { // log.Println(string(response), err) // return false, err // } if helper.ToStr(response.Code) != "OK" { return false, errors.New("短信发送失败," + helper.ToStr(response.Message)) } return true, nil }