Overview
All the examples in this document are based on
java servlet
.
Development environment
Item | Description |
---|---|
compatibility | JAVA SE 1.6 or higher |
Dependency | java-json.jar、servlet-api.jar |
Web server | tomcat 7 or higher |
Resources
Item | Description |
---|---|
Data communication flow chart | Data Communication flow chart |
Download SDK | gt3-server-maven-sdk |
Installation
Download SDK
There are two ways to download SDK.
Use command line to get from Github
git clone https://github.com/GeeTeam/gt3-server-maven-sdk.git |
Download SDK manually
Get the latest SDK from Github: gt3-server-maven-sdk (in .zip
format).
Import SDK
Copy and paste /src/main/java/com/geetest/sdk/GeetestLib.java
into your project.
Import the SDK
import com.geetest.sdk.GeetestLib |
Configure key pair and modify the request
Configure key pair
Get your key pair from GeeTest Dashboard. The key pair consists of a public key(captcha ID) and a private key (KEY). Then, configure the key pair in the following path.
/src/main/java/com/geetest/demo/GeetestConfig.java |
Modify the request (optional)
Variable | Description |
---|---|
user_id | User identification. If you concern about the risk of user information, you can preprocess (e.g. hashed) it. |
client_type | Type of client. Web (web browser for computers),h5 (mobile browser,including webview),native(native mobile app),unknown (unknow client type) |
ip_address | IP address for client requesting your server , unknow means unknow IP address |
API example
Captcha initialization
Initiate captcha via API1, get challenge
and set the status
.
public class FirstRegisterServlet extends HttpServlet { |
Notice:
status
indicates the status of API1.1
represents normal status, or0
represents downtime.
gtServerStatus
is stored in session from API1. API2 will read the value from session and check the status.1
will start the 2nd verification process.0
will start the fail-back mode.
success
is the value that API1 returns to the front-end.1
shows normal page and0
shows downtimw page.
Secondary verification (API2), including uptime and downtime
public class SecondValidateServlet extends HttpServlet { |
Notice: When
status = 0
, it means GeeTest server experiencing downtime and it will go to failback mode. No more requests will be made to GeeTest server.How to simulate the Failback mode? Please fill in an incorrect string (e.g. 123456789) for the captcha ID. Then, it will enter the Failback mode.
Run demo
Export demo in .war
format and put it under tomcat7/webapps. Then start tomcat.
To view the demo, please visit http://localhost:8080/gt3-server-maven-sdk
in browser.
Troubleshooting: secondary verification failure
- SDK internal logic errors. Please check: a) whether
session
is stored and read successfully, b) whether the code could successfully proceed to the module which send a request to GeeTest server, c) check the return value of GeeTest server. - Multiple submission. The API which initiates the secondary verification is only available for one time.
- The
challenge
is inconsistent. Please ensure the consistency ofchallenge
during the whole verification process. - Check if
gt
andkey
in the code are correct in SDK. Please check if the parameters have been passed correctly. - Please provide
challenge
to our service team. They could help you to check the log.