使用 cloud.AliSMS{} 对象可以快速实现基于阿里的验证短信发送功能。
参数 :
PhoneNumbers string 手机号码
TemplateParam string 模板参数
package main
import (
"fmt"
"strconv"
"github.com/cnlesscode/gotool/cloud"
"github.com/cnlesscode/gotool/random"
)
func main() {
aliSMS := &cloud.AliSMS{
AccessKeyId: "******",
AccessKeySecret: "******",
Endpoint: "dysmsapi.aliyuncs.com",
SignName: "阿里云短信测试专用",
TemplateCode: "SMS_8******8",
}
code := random.RangeIntRand(111111, 999999)
codeString := strconv.Itoa(int(code))
err := aliSMS.Send("181********", "{\"code\":\""+codeString+"\"}")
fmt.Printf("err: %v\n", err)
}