|
|
@ -1,16 +1,14 @@ |
|
|
|
package sms |
|
|
|
|
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"log" |
|
|
|
|
|
|
|
"git.tetele.net/tgo/helper" |
|
|
|
|
|
|
|
dysmsapi "github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi" |
|
|
|
"errors" |
|
|
|
"git.tetele.net/tgo/helper" |
|
|
|
dysmsapi "github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi" |
|
|
|
"log" |
|
|
|
) |
|
|
|
|
|
|
|
/** |
|
|
|
* 企业信息服务平台--阿里云短信,九江食堂用 |
|
|
|
* 阿里云短信 |
|
|
|
* @accessKeyId 用来验证用户身份的keyId |
|
|
|
* @accessKeySecret 用来验证用户身份的secret |
|
|
|
* @signName 短信签名名称 |
|
|
@ -19,36 +17,36 @@ import ( |
|
|
|
* @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", "<your-access-key-id>", "<your-access-key-secret>", "<your-sts-token>") |
|
|
|
*/ |
|
|
|
|
|
|
|
request := dysmsapi.CreateSendSmsRequest() |
|
|
|
request.Scheme = "https" |
|
|
|
|
|
|
|
request.PhoneNumbers = phoneNumbers //"1368846****" //接收短信的手机号码
|
|
|
|
request.SignName = signName //"阿里云" //短信签名名称
|
|
|
|
request.TemplateCode = templateCode //"SMS_20933****" //短信模板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 |
|
|
|
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", "<your-access-key-id>", "<your-access-key-secret>", "<your-sts-token>") |
|
|
|
*/ |
|
|
|
|
|
|
|
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 |
|
|
|
} |