<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
-keep class com.**.TNative$aa { public *; }-keep class com.**.TNative$aa$bb { public *; }-keep class com.**.TNative$bb { *; }-keep class com.**.TNative$bb$I { *; }
dependencies {implementation fileTree(dir: 'libs', include: ['*.aar'])}defaultConfig {ndk {abiFilters "armeabi-v7a", "arm64-v8a"}}
<WebViewandroid:id="@+id/tcaptchaWebview"android:layout_width="match_parent"android:layout_height="match_parent"/>
// InitializeTencentCaptchaConfig.BuilderconfigBuilder =newTencentCaptchaConfig.Builder(getApplicationContext(),newITencentCaptchaPrivacyPolicy(){...},newICaptchaDeviceInfoProvider(){...});RetCoderet =TencentCaptcha.init(config.build());...// Required parametersTencentCaptchaParam.BuildertencentCaptchaBuilder =newTencentCaptchaParam.Builder().setWebView(tcaptchaWebView).setCaptchaAppid(CaptchaAppid);// Business startTencentCaptcha.start(callback,tencentCaptchaBuilder.build());
TencentCaptchaCallback callback = new TencentCaptchaCallback() {@Overridepublic void finish(RetCode ret, JSONObject resultObject) {...}@Overridepublic void exception(Throwable t) {...}};
Class | Description |
TencentCaptcha | Main entry class of SDK |
TencentCaptchaConfig | SDK initialization configuration |
TencentCaptchaCallback | SDK result callback |
TencentCaptchaParam | SDK Captcha input parameters |
/***Initialize with the built configuration** @param TencentCaptchaConfig* @return RetCode*/RetCode init(TencentCaptchaConfig);/*** Start Captcha detection** @param TencentCaptchaCallback* @param TencentCaptchaParam* @return RetCode*/RetCode start(TencentCaptchaCallback, TencentCaptchaParam);/*** Interrupt detection process*/void stop();
/*** Create a TencentCaptcha.Builder object.** @param Context* @param ITencentCaptchaPrivacyPolicy API instance, [must pass implementation], any API call of the SDK will use this instance to ask the user if they have agreed to the privacy policy* @param ICaptchaDeviceInfoProvider API instance, pass ANDROIDID, used for the validity check of the device identifier itself and to identify abnormal device environments to detect device risks*/*/Builder(Context, ITencentCaptchaPrivacyPolicy,ICaptchaDeviceInfoProvider);
/*** Callback when Captcha verification ends, notifying the host to obtain verification ticket and other information.** @param RetCode, when RetCode is not OK, please refer to [retcode values] section* @param JSONObject, when RetCode is OK, please refer to [JSONObject return values] section for information*/void finish(RetCode, JSONObject);/*** Callback when an exception occurs in the SDK working thread** @param Throwable*/void exception(Throwable);
/*** Create a TencentCaptchaParam.Build object.** @return TencentCaptchaParam*/TencentCaptchaParam build();/*** Set the CaptchaAppid, obtained from the tencent cloud console. Without this, the SDK will not work properly.** @param String, CaptchaAppid.* @return Build*/Builder setCaptchaAppid(String);/*** Set the WebView to display the Captcha.** @param webView* @return Builder*/Builder setWebView(WebView);
TencentCaptchaConfig.Builder configBuilder = newTencentCaptchaConfig.Builder(getApplicationContext(),new ITencentCaptchaPrivacyPolicy() {@Overridepublic boolean userAgreement() {// Authorization Passed// true indicates authorization passed, the SDK can be used normally// false indicates unauthorized, subsequent calls to the start method will throw an exceptionreturn false;}},new ICaptchaDeviceInfoProvider() {@Overridepublic String getAndroidId() {return androidId; // Implementation to get AndroidId}});
// Initialize the SDKRetCode ret = TencentCaptcha.init(configBuilder.build());if(ret == RetCode.OK) {// Initialized successfully} else {// Initialization failedlog.error("ret code: " + ret.getCode() + " msg:" + ret.getMsg()); }
TencentCaptchaCallback callback = new TencentCaptchaCallback() {@Overridepublic void finish(RetCode ret, JSONObject resultObject) {if (ret == RetCode.OK) {// Success, execute business logic} else {// Failedlog.error("code:" + ret.getCode() + " msg:" + ret.getMsg());}}@Overridepublic void exception(Throwable t) {// Abnormalt.printStackTrace();}};
TencentCaptchaParam.Builder paramBuilder = newTencentCaptchaParam.Builder().setWebView(tcaptchaWebView) // required, WebView to display Captcha.setCaptchaAppid("CaptchaAppid"); // required, CaptchaAppid
TencentCaptcha.start(callback, paramBuilder.build());
@Overrideprotected void onPause() {super.onPause();TencentCaptcha.stop();}
/*** Get Error Code** @return int*/int getCode();/*** Get Detailed Error Information** @return String*/String getMsg();
Retcode Values | code | Description |
OK | 0 | Succeeded |
INIT_FAILED | 1 | Initialization failed |
NOT_INIT | 2 | Uninitialized |
INVALID_PARAMS | 3 | Invalid Input Parameters |
INVALID_WEBVIEW | 4 | Webview Is Empty |
CAPTCHA_RETDATA_EMPTY | 5 | Captcha return parameter is empty |
CAPTCHA_EXCEPTION | 6 | Captcha detection exception |
POLICY_ERROR | 7 | Privacy terms not agreed |
Field Name | Value Type | Description |
ret | Int | Verification result, 0: Verification successful. |
ticket | String | Ticket returned by Captcha, ticket has value only when ret = 0. |
CaptchaAppId | String | Captcha Application ID. |
bizState | Any | Custom pass-through parameters. |
randstr | String | Random string for this verification, this parameter needs to be passed during subsequent ticket verification. |
errorCode | Number | Error code, for details, see the callback function errorCode description. |
errorMessage | String | Error message. |
/*** Custom pass-through parameters, this field can be used by the business to pass a small amount of data, and the content of this field will be included in the callback object.** @param Object* @return Builder*/Builder setBizState(Object);/*** true: Enable adaptive night mode.** @param boolean* @return Builder*/Builder setEnableDarkMode(boolean);/*** "force": Enable forced night mode.** @param String* @return Builder*/Builder setEnableDarkMode(String);/*** false: Hide the help button.** @param boolean* @return Builder*/Builder setNeedFeedBack(boolean);/*** Custom help link: "URL".** @param String* @return Builder*/Builder setNeedFeedBack(String);/*** Specify the language of the Captcha prompt text, which takes precedence over console configuration.* Supports passing the same value as navigator.language, the user's preferred language, case-insensitive.* For details, see https://www.tencentcloud.com/zh/document/product/1159/49680?lang=zh&pg=#userLanguage.** @param String* @return Builder*/Builder setUserLanguage(String);/*** true: enable aging adaptation* false: disable aging adaptation** @param boolean* @return Builder*/Builder setEnableAged(boolean);/*** Define the Captcha display method.* popup: (default) Popup, displays the Captcha in a centered floating layer.* full: Full Screen** @param String* @return Builder*/Builder setType(String);/*** Whether to show loading box during Captcha loading. If this parameter is not specified, the loading box is shown by default.* true: show loading box* false: do not show loading box** @param boolean* @return Builder*/Builder setLoading(boolean);/*** Set CaptchaAppId encrypted verification string, see encryption verification capability access guide for details** @param String* @return Builder*/Builder setAidEncrypted(String);/*** Callback for some internal Captcha information, see [TencentCaptchaParam.OptionsCallback description] for details.** @param OptionsCallback* @return Builder*/Builder setOptionsCallback(OptionsCallback);
/*** 1. When optFuncName is ready,* data returns the callback when the Captcha is loaded, with the actual width and height of the Captcha (unit: px):* {"sdkView": {* "width": number,* "height": number* }}* This parameter is only for viewing the Captcha dimensions, do not use this parameter to set the dimensions directly.* 2. When optFuncName is showFn, data returns duration, rendering time + sid information.** @param optFuncName, String* @param data, String*/void onCallback(String optFuncName, String data); result callback, return value
Was this page helpful?