Integrate the .NET server-side SDK

更新时间:
复制 MD 格式

The `IClientProfile` interface is used to interact with the Alibaba Cloud Captcha server-side API and perform all SDK operations.

Prerequisites

  • An AccessKey has been created for your Alibaba Cloud account.

  • You have downloaded the .NET server-side software development kit (SDK) package from the Alibaba Cloud Captcha console.

  • The server-side development environment requires .NET Framework 4.0 or later.

Install the SDK

  1. Locate the `aliyun-net-sdk-afs.dll` and `aliyun-net-sdk-core.dll` files in the extracted SDK package.

  2. Import these two files into your server-side project.

    For example, in Visual Studio, right-click Project, select Add Reference > Browse, and then select and add the two .dll files.

  3. After the files are added, you can use the Alibaba Cloud Captcha .NET SDK in your server-side project.

Notes

  • The classes for the Alibaba Cloud Captcha server-side SDK are in the `com.aliyuncs.IAcsClient` package.

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

Initialize IClientProfile

Note

`IClientProfile` is reusable. You should set it as a globally unique object for the application.

String regionid = "cn-hangzhou";
String accessKeyId = "*** Provide your AccessKeyId ***";
String accessKeySecret = "*** Provide your AccessKeySecret ***";
// Create a new IClientProfile instance
IClientProfile profile= DefaultProfile.getProfile(regionid, accessKeyId, accessKeySecret);
IAcsClient client = new DefaultAcsClient(profile);
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "afs", "afs.aliyuncs.com");

Call the Alibaba Cloud Captcha server-side API

After `IClientProfile` is initialized, you can call the Alibaba Cloud Captcha server-side APIs. You also need to develop a handler class for frontend page requests and a method to process the results.

For more information about the Alibaba Cloud Captcha service APIs, see Alibaba Cloud Captcha service APIs for web and HTML5 applications.

public void Test()
      {
          AuthenticateSigRequest request = new AuthenticateSigRequest();
          request.SessionId = "xxx";// The session ID. Required. Obtain from the frontend. Do not change.
          request.Sig = "xxx";// The signature string. Required. Obtain from the frontend. Do not change.
          request.Token = "xxx";// The unique request ID. Required. Obtain from the frontend. Do not change.
          request.Scene = "xxx";// The scene ID. Required. Obtain from the frontend. Do not change.
          request.AppKey = "xxx";// The application type ID. Required. Specify on the backend.
          request.RemoteIp = "xxx";// The client IP address. Required. Specify on the backend.
          try
          {
          // Response code enumeration: 100 for successful signature verification, 900 for failed signature verification.
              AuthenticateSigResponse response = client.GetAcsResponse(request);
              // TODO
          }
          catch (Exception e)
          {
              Console.WriteLine(e.ToString());
          }
      }