> >

Captcha Android API Document

GTCaptcha4Client

Classes of Main External Support Tools classes for Captcha 4.0

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

Declaration

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

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 GTCaptcha4Client addOnWebViewShowListener(GTCaptcha4Client.OnWebViewShowListener listener)

Parameters

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

verifyWithCaptcha()

Start the verification and load the captcha

Declaration

public GTCaptcha4Client verifyWithCaptcha()

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 void cancel()

Discussion

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

setLogEnable(boolean enable)

Set the print log monitoring on/off

Declaration

public void setLogEnable(boolean enable)

Discussion

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

destroy()

Destroy resources with long life cycle

Declaration

public 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 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 Builder setTimeOut(int timeOut)

Parameters

Param Type Description
timeOut int Unit ms, 10000 by default

setResourcePath(String)

Set WebView, load resource address

Declaration

public 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 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 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 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 Builder setBackgroundColor(int backgroundColor)

Parameters

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

setDialogStyle(String)

Set theme style for the Captcha dialog

Declaration

public Builder setDialogStyle(String dialogStyle)

Parameters

Param Type Description
dialogStyle String the theme style of the Captcha dialog

Declaration

here is the default theme style

<style name="gt4_captcha_dialog_style" parent="android:Theme.Dialog">

<item name="android:windowFrame">@null</item>

<item name="android:windowIsFloating">true</item>

<item name="android:windowIsTranslucent">true</item>

<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>

<item name="android:backgroundDimEnabled">true</item>

<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:padding">0dp</item>
</style>

setDialogShowListener(GTCaptcha4Client.OnDialogShowListener)

Set the listening callback displayed in the verification window

Declaration

public void setDialogShowListener(GTCaptcha4Client.OnDialogShowListener dialogShowListener)

Parameters

Param Type Description
dialogShowListener GTCaptcha4Client.OnDialogShowListener The listener object of the verification window to show

setParams(Map<string, object>)

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

Declaration

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

Parameters

Param Type Description
params JSONObject Additional configuration parameter

Discussion

Supported key-values:

Key ValueType Description Default Value
displayMode int 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 float 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

Map<String, Object> params = new HashMap<>();
params.put("displayMode", 0);
params.put("protocol", "https://");
params.put("bgColor", "#CC0000FF");
params.put("loading", "./loading_test.gif");
params.put("rem", 0.6);
JSONArray hideBar = new JSONArray()
.put("close")
.put("refresh");
params.put("hideBar", hideBar);
params.put("nextWidth", "300px");
params.put("hideSuccess", true);

GTCaptcha4Config.Builder builder = new GTCaptcha4Config.Builder()
.setParams(params);

build()

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

Declaration

public 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":"Captcha session is canceled","desc":{"description":"User cancelled 'Captchas'"}}

GTCaptcha4Client#OnWebViewShowListener

Load succeed callback listener method

onWebViewShow()

load succeed callback

Declaration

void onWebViewShow()

Discussion

it will be called after the captcha is successfully loaded. if the captcha is preloaded succeed, it will be called after verifyWithCaptcha() is executed.

GTCaptcha4Client#OnDialogShowListener

the listening callback displayed in the verification window

actionBeforeDialogShow(Dialog)

The verification window is called back before it is displayed

Declaration

void actionBeforeDialogShow(Dialog dialog)

Parameters

Param Type Description
dialog Dialog verification window object

actionAfterDialogShow()

Callback after the verification window is displayed

Declaration

void actionAfterDialogShow(Dialog dialog)

Parameters

Param Type Description
dialog Dialog verification window object

Discussion

You can change the system style here, such as hiding the navigation bar, hiding the status bar, etc

onDialogFocusChanged()

Verification window callback when changing focus

Declaration

void onDialogFocusChanged(Dialog dialog, boolean hasFocus)

Parameters

Param Type Description
dialog Dialog verification window object
hasFocus boolean Whether there is focus
Was this helpful?
Send