Integrate the server-side SDK for NodeJS

更新时间:
复制 MD 格式

This topic describes how to integrate the Captcha server-side SDK in a NodeJS environment.

Prerequisites

Install the SDK

  1. Find the client file in the unzipped SDK package.

  2. 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.

Note

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)
})