posts - 22,comments - 0,trackbacks - 0

话不多说,直接上代码!!!

要先下载两个包 (可以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数据解析
}

 

posted on 2019-11-09 18:11  可惜啊。  阅读(...)  评论(... 编辑 收藏