话不多说,直接上代码!!!
要先下载两个包 (可以go get -u +你想要的包)
github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests
github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi
package main import ( "fmt" "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" "github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi" ) func main() { client, err := dysmsapi.NewClientWithAccessKey("cn-beijing", "阿里云的accessKeyId", "accessKeySecret") request := requests.NewCommonRequest() request.Method = "POST" request.Scheme = "https" // https | http request.Domain = "dysmsapi.aliyuncs.com" request.Version = "2017-05-25" request.ApiName = "SendSms" request.QueryParams["RegionId"] = "cn-beijing" request.QueryParams["PhoneNumbers"] = "xxxxxx" //手机号 request.QueryParams["SignName"] = "xxxxx" //阿里云验证过的项目名 自己设置 request.QueryParams["TemplateCode"] = "xxx" //阿里云的短信模板号 自己设置 request.QueryParams["TemplateParam"] = "{\"code\":" + "777777" + "}" //短信模板中的验证码内容 自己生成 之前试过直接返回,但是失败,加上code成功。 response, err := client.ProcessCommonRequest(request) fmt.Print( client.DoAction(request, response)) // fmt.Print(response) if err != nil { fmt.Print(err.Error()) } fmt.Printf("response is %#v\n", response) //json数据解析 }
原文地址:https://www.cnblogs.com/zxs117/p/11827174.html
时间: 2024-11-06 07:26:06