Skip to content
breakawayz edited this page Jan 14, 2018 · 9 revisions

Go SDK 使用说明

欢迎使用SMN服务Go SDK。SMN服务Go SDK 能简化你使用SMN服务的复杂程度。这里向您介绍如何使用Go SDK 并开始调用。

环境准备

  • 1、Go语言运行环境
  • 2、您需要一个华为云账号。

SDK 获取和安装

使用go get下载安装SDK

go get -u github.com/SimpleMessageNotification/smn-sdk-go/smn-sdk-go

开始使用

以下这个代码示例向您展示了调用SMN服务SDK 的 3 个主要步骤:

  • 创建服务client实例
  • 设置配置对象和请求对象
  • 发送请求并处理

发送短信样例

package main

import (
	"github.com/smn-sdk-go/smn-sdk-go/client"
	"fmt"
)

func main() {
	// init client, you can init client only once
	smnClient, err := client.NewClient(
		"YourAccountUserName",
		"YourAccountDomainName",
		"YourAccountPassword",
		"YourRegionName")
	if err != nil {
		panic(err)
	}

	request := smnClient.NewSmsPublishRequest()
	request.EndPoint = "+86136*****587"
	request.SignId = "6be340e91e524******85837e6709104"
	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或输入参数相关问题,请查阅API文档