Go server-side SDK integration

更新时间:
复制 MD 格式

This topic describes how to integrate the No-Captcha server-side SDK for Go.

Prerequisites

  • You have generated an AccessKey for your Alibaba Cloud account.

  • You have downloaded and unzipped the Go server-side SDK package.

  • The version of your server-side developer environment is 1.12.0 or later.

Install the SDK

  1. Find the client file in the unzipped SDK package.

  2. Import the client package into your server-side project.

After you import the package, you can use the Alibaba Cloud Captcha Go SDK in your server-side project.

Notes

  • Classes related to the Alibaba Cloud Captcha server-side SDK are in the client package.

  • The default connection timeout for SDK API calls is 3 seconds, and the read timeout is 80 seconds. To customize these timeouts, call the constructor with the connectTimeout and readTimeout parameters.

Initialize IClientProfile

IClientProfile is the interface for interacting with the Alibaba Cloud Captcha server-side. All SDK operations are performed using this interface.

Note

IClientProfile can be reused. We recommend that you set it as a globally unique object for your application.

import (
  "fmt"
   afs "Alibaba Cloud Captcha package"
   rpc
)
/**
Example
import (
 fmt "fmt"
 afs "github.com/alibabacloud-go/afs-20180112/client"
 rpc "github.com/alibabacloud-go/tea-rpc/client"
)
 */
config := new(rpc.Config)
config.SetAccessKeyId("*** Provide your AccessKeyId ***").
     SetAccessKeySecret("*** Provide your AccessKeySecret ***").
     SetRegionId("cn-hangzhou").
     SetEndpoint("afs.aliyuncs.com")
client, _ := afs.NewClient(config)

Call the Alibaba Cloud Captcha server-side API

After you initialize IClientProfile, call the AnalyzeNvc operation. You must also develop a handler for frontend page requests and a method to process the results.

request := new(afs.AnalyzeNvcRequest)
request.SetData("xxx")
request.SetScoreJsonStr("{\"200\":\"PASS\",\"400\":\"NC\",\"800\":\"BLOCK\"}")
response, _err := client.AnalyzeNvc(request)
fmt.Println(response)