Step By Step
1、SDK下载
go get -u github.com/aliyun/alibaba-cloud-sdk-go/sdk
2、Code Sample
package main
import (
"fmt"
"time"
"github.com/aliyun/alibaba-cloud-sdk-go/services/onsmqtt"
)
func main() {
client, err := onsmqtt.NewClientWithAccessKey("mq-internet-access", "<accesskey>", "<accesssecret>")
request := onsmqtt.CreateApplyTokenRequest()
request.Scheme = "http"
request.Resources = "demo-test/+"
request.InstanceId = "post-cn-6ja********"
request.ExpireTime = "<毫秒时间戳>"
request.Actions = "R,W"
var t int32
t = 60
request.ConnectTimeout = time.Duration(t) * time.Second
response, err := client.ApplyToken(request)
if err != nil {
fmt.Print(err.Error())
}
fmt.Printf("response is %#v\n", response)
}
3、测试结果