> >

Captcha Harmony API Document

GTCaptcha4Client

Classes of Main External Support Tools classes for Captcha 4.0

getClient(UIContext)

Getting the GTCaptcha4Client tool class object

Declaration

public static getClient(context UIContext): GTCaptcha4Client

Parameters

Param Type Description
context UIContext UIContext

Discussion

Note: Non-singleton implementation, the GTCaptcha4Client object retrieved through getClient () needs to be saved for use in onDestory or other lifecycle

init(string, GTCaptcha4Config)

Initialize using the default configuration

Declaration

public init(captchaId: string, config: GTCaptcha4Config): GTCaptcha4Client

Parameters

Param Type Description
captchaId string CaptchaId applied in the background
config GTCaptcha4Config Parameter Configuration Object

addOnSuccessListener(GTCaptcha4Client.OnSuccessListener)

Add verification result monitoring object. When the verify is submitted successfully, the user’s answer to the captcha will be called back

Declaration

public addOnSuccessListener(response: OnSuccessListener): GTCaptcha4Client

Parameters

Param Type Description
response GTCaptcha4Client.OnSuccessListener Captcha Result Listening Object

addOnFailureListener(GTCaptcha4Client.OnFailureListener)

Add a listening object for loading captcha failure, and report errors that occurred during captcha loading

Declaration

public addOnFailureListener(listener: OnFailureListener): GTCaptcha4Client

Parameters

Param Type Description
listener GTCaptcha4Client.OnFailureListener Listening object for loading captcha failure

addOnWebViewShowListener(GTCaptcha4Client.OnWebViewShowListener)

Add a listening object for loading captcha successfully. if the captcha is preloaded succeed, it will be called after verifyWithCaptcha() is executed.

Declaration

public addOnWebViewShowListener(listener: OnWebViewShowListener): GTCaptcha4Client

Parameters

Param Type Description
listener GTCaptcha4Client.OnWebViewShowListener Listening object for loading captcha succeed

verifyWithCaptcha()

Start the verification and load the captcha

Declaration

public verifyWithCaptcha(): GTCaptcha4Client

Discussion

Note: Before calling verifyWithCaptcha (), you need to call init (), addOnSuccessListener (), addOnFailureListener or you may encounter an error

cancel()

Cancel the verification and close window

Declaration

public cancel()

Discussion

Note: Before calling cancel (), you need to call init (), addOnSuccessListener (), addOnFailureListener or you may encounter an error

setLogEnable(enable: boolean)

Set the print log monitoring on/off

Declaration

public setLogEnable(enable: boolean): GTCaptcha4Client

Discussion

Note: Calling ‘setLogEnable’ will control the log printing function

destroy()

Destroy resources with long life cycle

Declaration

public destroy()

Discussion

This method is called in the destroy life cycle of the captcha interface used by the customer

getVersion()

Get version number

Declaration

public static getVersion(): string

Return Value

Returns the version number, the type is String

GTCaptcha4Config

Configuring parameters

setTimeOut(number)

Set the request timeout

Declaration

setTimeOut(timeOut: number): GTCaptcha4Config

Parameters

Param Type Description
timeOut number Unit ms, 10000 by default

setResourcePath(string)

Set WebView, load resource address

Declaration

setResourcePath(html: string): GTCaptcha4Config

Parameters

Param Type Description
html string WebView Load Address

setLanguage(string)

Transfer the setting language of JS, this interface can only control the language in which WebView is loaded, and the multi-language of SDK follows the current application

Declaration

setLanguage(language: string): GTCaptcha4Config

Parameters

Param Type Description
language string The front-end supports short language codes. See the front-end documents for details

Discussion

If it is set to null or not set, the application default language short code is used for transmission to the front end.

setIsCanceledOnTouchOutside(boolean)

Set whether the gray area disappears when clicking, and it disappears by default

Declaration

setIsCanceledOnTouchOutside(isCanceledOnTouchOutside: boolean): GTCaptcha4Config

Parameters

Param Type Description
isCanceledOnTouchOutside boolean true indicates that gray area disappears

setIsDebug(boolean)

Set the debug mode, make sure configuration is set to false when going online, or do not set it.

Declaration

setIsDebug(isDebug: boolean): GTCaptcha4Config

Parameters

Param Type Description
debug boolean true indicates debug mode, and the default is false

setBackgroundColor(number)

Set the WebView background color, and control the background color of the Android WebView control, which is different from the background color of the front-end JS.

Declaration

setBackgroundColor(backgroundColor: string): GTCaptcha4Config

Parameters

Param Type Description
backgroundColor string color resource

setParams(Map<string, Object>)

Extra parameter configuration, the current parameter is completely transferred to JS

Declaration

setParams(params: Map<string, Object>): GTCaptcha4Config

Parameters

Param Type Description
params JSONObject Additional configuration parameter

Discussion

支持的键值如下表:

Key ValueType Description Default Value
displayMode number Theme Style, 0: System 1: Normal 2: Dark 0
protocol string The protocol of requests. "https:// or http://. https://
bgColor string Captcha background color. Following css rules, such as "#000000ff" "#00000000"
loading string Custom loading, the relative path of loading resource of html is loaded by Webview. The empty string refers to cancel the effect of loading. "/gt4-loading.gif"
rem number Set the overall scaling ratio of the captcha 1
nextWidth string The width of the captcha pop-up window. The unit is needed, such as “300px”. N/A
riskType string Conbined with Direct Platform Integration, specify the CAPTCHA form. N/A
hideSuccess boolean Hide the verification success window FALSE

Sample Code

let params = new Map<string, string>();
params.set("displayMode", 0);
params.set("protocol", "https://");
params.set("bgColor", "#CC0000FF");
...

let gtcaptcha4Config = new GTCaptcha4Config()
.setParams(params);

GTCaptcha4Client#OnSuccessListener

Captcha results callback listener method

onSuccess(Boolean, string)

Captcha interface callback

Declaration

onSuccess: (status: boolean, response: string) => void;

Parameters

Param Type Description
status boolean Verification results of user operation, true for success, false for failure, failure will refresh the verification style
response string If the user operation is verified successfully, the response data needs to be verified by the server

Discussion

The response that verification passes is as below:

{"lot_number":"b150e61198924eff9eaae121e9b67aa8","pass_token":"6fcfba4c35cb57b873c99c5b3b02089c58a26244c18f7706aaa1e87aed3aa8f4","gen_time":"1622020720","captcha_output":"Tu6rW0dRNO0NLxMKftwdH00G5whF5HHddthoXSEA1G4="}

The response that verification fails is as below:

{"captchaId":"647f5ed2ed8acb4be36784e01556bb71","captchaType":"slide","challenge":"95ed53b4-95c6-4c6b-9aac-769b29ef74a0"}

GTCaptcha4Client#OnFailureListener

Load failure callback listener method

onFailure(string)

Load failure callback

Declaration

onFailure: (error: string) => void;

Parameters

Param Type Description
error string Description of captcha load failure, note: including cancellation by users

Discussion

Load failure is described as:

{"code":"-14460","msg":"Captcha session is canceled","desc":{"description":"User cancelled 'Captchas'"}}

GTCaptcha4Client#OnWebViewShowListener

Load succeed callback listener method

onwebViewShow()

load succeed callback

Declaration

onWebViewShow: () => void;

Discussion

it will be called after the captcha is successfully loaded.

Was this helpful?
Send