.NET server-side SDK integration
The IClientProfile interface is used to interact with the Alibaba Cloud Captcha server-side API. All SDK operations are performed using IClientProfile.
Prerequisites
You have an AccessKey for your Alibaba Cloud account.
You have downloaded the .NET server-side SDK package from the Alibaba Cloud Captcha console.
The server-side development environment is .NET Framework 4.0 or later.
Install the SDK
In the unzipped SDK package, find the aliyun-net-sdk-afs.dll and aliyun-net-sdk-core.dll files.
Import these two files into your server-side project.
For example, in Visual Studio, right-click Project, select Add Reference > Browse, and then select the two DLL files and add them.
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 default read timeout is 80 seconds. You can call the constructor with connectTimeout and readTimeout to customize the connection and read timeouts.
Initialize IClientProfile
IClientProfile is reusable. We recommend that you 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 you initialize IClientProfile, you can call the APIs provided by the Alibaba Cloud Captcha service. You can also develop a handler class for frontend page requests and determine how to process the results.
For more information, see Alibaba Cloud Captcha service APIs for web and HTML5 applications.
public void Test()
{
AuthenticateSigRequest request = new AuthenticateSigRequest();
request.SessionId = "xxx";// The session ID. This parameter is required. Obtain it from the frontend. Do not change the value.
request.Sig = "xxx";// The signature string. This parameter is required. Obtain it from the frontend. Do not change the value.
request.Token = "xxx";// The unique request token. This parameter is required. Obtain it from the frontend. Do not change the value.
request.Scene = "xxx";// The scene identifier. This parameter is required. Obtain it from the frontend. Do not change the value.
request.AppKey = "xxx";// The application type identifier. This parameter is required. Specify this on the backend.
request.RemoteIp = "xxx";// The client IP address. This parameter is required. Specify this on the backend.
try
{
// Response code enumeration: 100 indicates that signature verification is successful. 900 indicates that signature verification failed.
AuthenticateSigResponse response = client.GetAcsResponse(request);
// TODO
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}