Integrate the .NET server-side SDK
This topic describes how to integrate the .NET server-side software development kit (SDK).
Prerequisites
An AccessKey has been created for your Alibaba Cloud account. For more information, see Create an AccessKey.
You have downloaded the .NET server-side SDK package from the Alibaba Cloud Captcha console.
Your server-side development environment is .NET Framework 4.0 or a later version.
Install the SDK
In the decompressed SDK package, find the aliyun-net-sdk-afs.dll and aliyun-net-sdk-core.dll files.
Import the 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.
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 interface calls is 3 seconds, and the default read timeout is 80 seconds. To customize these timeouts, call the constructor with the connectTimeout and readTimeout parameters.
Initialize IClientProfile
The IClientProfile interface is used to interact with the Alibaba Cloud Captcha server. All SDK operations are performed through this interface.
The IClientProfile interface is reusable. We recommend that you configure it as a globally unique object for your 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 interface
After you initialize IClientProfile, you can call the AnalyzeNvcRequest interface. Then, you can develop a handler class for frontend page requests and a method to process the results based on your requirements.
public void Test()
{
AnalyzeNvcRequest request = new AnalyzeNvcRequest();
request.Data = "xxx"; // Required. The value is obtained from the frontend using the getNVCVal method.
// Use the setScoreJsonStr method to declare the mapping between the results returned by the Captcha server and the operations to be performed on the frontend. This also notifies the Captcha server to grant authorization for secondary authentication.
// Note: The frontend page must perform operations in strict accordance with this mapping. Otherwise, call exceptions may occur.
// For example, if you declare "400":"NC" in the setScoreJsonStr method, your frontend must initiate No-Captcha (NC) verification when the server returns 400. If you initiate another type of verification, the call fails.
request.ScoreJsonStr("{\"200\":\"PASS\",\"400\":\"NC\",\"800\":\"BLOCK\"}"); // Set the client-side actions that correspond to different results as needed.
try
{
AnalyzeNvcResponse response = client.GetAcsResponse(request);
// TODO
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}