Node.js server-side SDK integration
This topic describes how to integrate the server-side software development kit (SDK) for Captcha with your Node.js application.
Prerequisites
An AccessKey has been created for your Alibaba Cloud account.
You have downloaded and decompressed the Node.js server-side SDK package.
Install the SDK
Find the client file in the decompressed SDK package.
Import the client package into your server-side project.
After you import the package, you can use the Alibaba Cloud Captcha SDK for Node.js in your server-side project.
Notes
The client package contains the classes for the Alibaba Cloud Captcha server-side SDK.
Initialize IClientProfile
IClientProfile is the interface for interacting with the Alibaba Cloud Captcha server-side. You can use it to perform all SDK operations.
IClientProfile is reusable. Set it as a globally unique object for your 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 interface. You may also need to develop a handler class for frontend page requests and a method to process the results.
// AuthenticateSigRequest
var data = new afs.AuthenticateSigRequest({
scene:'xxx',
sessionId:"xxx",
sig:"xxx",
appKey: "xxx",
token: "xxx",
remoteIp: "xxx"
})
// AuthenticateSigResponse
var response;
client.authenticateSig(data).then(function(result){response = result;console.log(response)})