Repository navigation
Home
SimpleMessageNotification edited this page Dec 11, 2017
·
9 revisions
欢迎使用SMN服务Go SDK。SMN服务Go SDK 能简化你使用SMN服务的复杂程度。这里向您介绍如何使用Go SDK 并开始调用。
- 1、Go语言运行环境
- 2、您需要一个华为云账号。
使用go get下载安装SDK
go get -u github.com/SimpleMessageNotification/smn-sdk-go/smn-sdk-go
以下这个代码示例向您展示了调用SMN服务SDK 的 3 个主要步骤:
- 创建服务client实例
- 设置配置对象和请求对象
- 发送请求并处理
package main
import (
"smn-sdk-go/client"
"fmt"
)
func main() {
// init client
smnClient , err := client.NewClient(
"youUserName",
"youDomainName",
"youPassword",
"cn-north-1"
)
if err != nil {
panic(err)
}
request := smnClient.NewSmsPublishRequest()
request.EndPoint = "+8613688807587"
request.SignId = "6be340e91e5241e4b5d85837e6709104"
request.Message = "您的验证码是:1234,请查收"
response, err := smnClient.SmsPublish(request)
if err != nil {
fmt.Println("the request is error ", err)
return
}
if !response.IsSuccess() {
fmt.Printf("%#v\n", response.ErrorResponse)
return
}
fmt.Printf("%#v\n", response)
}
API或输入参数相关问题,请查阅API文档