>

Android

Captcha Android API Document

GTCaptcha4Client

Classes of Main External Support Tools classes for Captcha 4.0

Method

getClient(Context)

Getting the GTCaptcha4Client tool class object

Declaration

public static GTCaptcha4Client getClient(Context context)

Parameters

Param Type Description
context Context Context

Discussion

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

init(String)

Initialize using the default configuration

Declaration

public final GTCaptcha4Client init(String captchaId)

Parameters

Param Type Description
captchaId String CaptchaId applied in the background

Discussion

Note: When the init () method is called, the captcha is loaded. If it is called before the onResume () life cycle, the captcha is preloaded. When verifyWithCaptcha () is executed to display the captcha, the captcha is loaded and displayed quickly. The same below.

init(String, GTCaptcha4Config)

Initialize using the custom configuration

Declaration

public final GTCaptcha4Client init(String captchaId, GTCaptcha4Config config)

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 captcha is loaded successfully, the user’s answer to the captcha will be called back

Declaration

public final GTCaptcha4Client addOnSuccessListener(GTCaptcha4Client.OnSuccessListener response)

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 final GTCaptcha4Client addOnFailureListener(GTCaptcha4Client.OnFailureListener listener)

Parameters

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

verifyWithCaptcha()

Start the verification and load the captcha

Declaration

public final GTCaptcha4Client verifyWithCaptcha()

Discussion

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

destroy()

Destroy resources with long life cycle

Declaration

public final void destroy()

Discussion

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

configurationChanged(Configuration)

Horizontal and vertical screen switching

Declaration

public final void configurationChanged(Configuration newConfig)

Discussion

This method is called in the onConfigurationChanged method when switching the horizontal and vertical screen

getVersion()

Get version number

Declaration

public static String getVersion()

Return Value

Returns the version number, the type is String

isSupportWebView(Context)

Check whether WebView is supported. If it is not supported, logic below is recommended

Declaration

public static Pair<Boolean, String> isSupportWebView(Context context)

Return Value

Pair Object Description

Param Type Description
first Boolean Check whether the WebView is supported. If not, the logic below is recommended
second String Load WebView, object error reporting description

GTCaptcha4Config#Builder

Configuring parameters

setTimeOut(int)

Set the request timeout

Declaration

public final Builder setTimeOut(int timeOut)

Parameters

Param Type Description
timeOut int Unit ms, 10000 by default

setResourcePath(String)

Set WebView, load resource address

Declaration

public final Builder setResourcePath(String html)

Parameters

Param Type Description
html String WebView Load Address

Discussion

The gt4-index.html file of the assets directory is loaded by default, and there is no need to set this interface if not necessary

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

public final Builder setLanguage(String language)

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.

setCanceledOnTouchOutside(boolean)

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

Declaration

public final Builder setCanceledOnTouchOutside(boolean canceledOnTouchOutside)

Parameters

Param Type Description
canceledOnTouchOutside boolean true indicates that gray area disappears

setDebug(boolean)

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

Declaration

public final Builder setDebug(boolean debug)

Parameters

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

setBackgroundColor(int)

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

public final Builder setBackgroundColor(int backgroundColor)

Parameters

Param Type Description
backgroundColor int Color resource address or Color.parseColor() return value

setParams(Map)

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

Declaration

public final Builder setParams(Map<String, Object> params)

Parameters

Key ValueType Description
displayMode int Current Theme Style, 0: System 1: Normal 2: Dark 3: Color Blind. Default is 0
displayArea String Center, bottom, center by default
protocol String https:// or http://, https:// by default
barHeight int Verification window downwards offset size, Unit: logical pixels, such as 14, and no configuration by default
bgColor String JS background color, following css rules, such as # 000000ff, and no configuration by default
loading String Custom loading, the relative loading path of the html loaded by the WebView, such as./loading.gif. Note: If remote html is loaded without this field, this field is not configured by default

Discussion

Describe with key-value pairs and support basic types, strings and JSONArray types

build()

Construct the GTCaptcha4Config object and pass it to the init () interface for use

Declaration

public final GTCaptcha4Config build()

GTCaptcha4Client#OnSuccessListener

Captcha results callback listener method

onSuccess(Boolean, String)

Captcha interface callback

Declaration

void onSuccess(Boolean status, String response)

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

void onFailure(String error)

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":"验证会话已取消","desc":{"description":"User cancelled 'Captchas'"}}
Was this helpful?
Send