Node.js server-side SDK integration

更新时间:
复制 MD 格式

This topic describes how to integrate the server-side software development kit (SDK) for Captcha with your Node.js application.

Prerequisites

Install the SDK

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

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

Note

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