NodeJS server-side SDK integration
This topic describes how to integrate the Captcha server-side software development kit (SDK) for NodeJS.
Prerequisites
An AccessKey is created for your Alibaba Cloud account.
The NodeJS server-side SDK package is downloaded and unzipped.
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 SDK for NodeJS 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. All SDK operations use this interface.
IClientProfile can be reused. Set it as a globally unique object 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 to process requests from your frontend pages and handle 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)})