Integrate the server-side SDK for NodeJS
This topic describes how to integrate the Captcha server-side SDK in a NodeJS environment.
Prerequisites
You have an AccessKey for your Alibaba Cloud account.
You have downloaded and unzipped the NodeJS server-side SDK package.
Install the SDK
Find the client file in the unzipped SDK package.
Import the client package into your server-side project.
After you add the package, you can use the Alibaba Cloud Captcha NodeJS SDK in your server-side project.
Notes
The classes related to the Alibaba Cloud Captcha server-side SDK are in the client package.
Initialize IClientProfile
IClientProfile is the interface for interacting with the Alibaba Cloud Captcha server. All SDK operations use IClientProfile.
IClientProfile is reusable. Set it as a global instance for the application.
var client = new afs.default({
accessKeyId: "*** Provide your AccessKeyId ***",
accessKeySecret: "*** Provide your AccessKeySecret ***",
endpoint: "afs.aliyuncs.com",
regionId:"cn-hangzhou"
})Call the Alibaba Cloud Captcha server-side API
After you initialize IClientProfile, call the AuthenticateSigRequest API. You also need to develop a handler class for frontend page requests and a method to process the results.
var data = new afs.AnalyzeNvcRequest({
sourceIp: 'xxx',
scoreJsonStr: 'xxx',
data: 'xxx',
})
var response;
client.analyzeNvc(data).then(function (result) {
response = result;console.log(response)
})