This topic provides a comprehensive guide on how to utilize Alibaba Cloud SMS SDK for Go. By incorporating this SDK as a dependency in your application, you can easily integrate the SendMessageToGlobe operation, enabling you to send SMS messages to various regions around the world, excluding the Chinese mainland.

Usage notes

  • You must set the regionId parameter to ap-southeast-1.
  • You must set the domain parameter to dysmsapi.ap-southeast-1.aliyuncs.com.
  • You must set the version parameter to 2018-05-01.

Sample code

package main

import (
    "fmt"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

func main() {
    client, err := sdk.NewClientWithAccessKey("ap-southeast-1", "<accessKeyId>", "<accessSecret>")
    if err != nil {
        panic(err)
    }

    request := requests.NewCommonRequest()
    request.Method = "POST"
    request.Scheme = "https" // https | http
    request.Domain = "dysmsapi.ap-southeast-1.aliyuncs.com"
    request.Version = "2018-05-01"
    request.ApiName = "SendMessageToGlobe"
    request.QueryParams["To"] = "62123****8901"
    request.QueryParams["RegionId"] = "ap-southeast-1"
    request.QueryParams["Message"] = "have a test."
    response, err := client.ProcessCommonRequest(request)
    if err != nil {
        panic(err)
    }
    fmt.Print(response.GetHttpContentString())
}