NodeJS server-side SDK integration

更新时间:
复制 MD 格式

This topic describes how to integrate the Captcha server-side software development kit (SDK) for NodeJS.

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

Note

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