SDK version | Capability Description | Scenario | Open or Not |
Basic Edition (BASIC) | OCR recognition of both sides of the ID + structured field extraction + ID authenticity verification (detection of recapture/photocopy/PS) + portrait cutout | General business scenarios with standard security requirements | Released. If SdkVersion is not specified, this edition is used by default. |
Enhanced Edition (ENHANCED) | All Basic capabilities + on-device risk information collection and reporting | Scenarios with higher security requirements, such as financial account opening and important account changes | Released |


Nationality (country/region code) and CardType (card type code) parameters to specify the document to be recognized. The currently supported combinations are as follows (the server will continuously add new card types, which take effect without requiring an upgrade by the business party):Nationality | Country/Region | CardType | Certificate Description |
CHN | Chinese mainland | ID_CARD,PERMIT | Resident identity card, mainland resident travel permit to Hong Kong and Macao (two-way permit) |
HKG | Hong Kong (China) | ID_CARD | Hong Kong (China) identity card |
MAC | Macao (China) | ID_CARD | Macao (China) identity card |
HKG / MAC / TWN | Hong Kong (China), Macao (China), and Taiwan (China) | MAINLAND_PERMIT,HMT_RESIDENT_PERMIT | Mainland travel permit for Hong Kong, Macao, and Taiwan residents (home return permit/Taiwan compatriot permit), residence permit for Hong Kong, Macao, and Taiwan residents |
THA | Thailand | ID_CARD,THA_PINK_CARD | Thai national ID card, Thai pink card |
IDN | Indonesia | ID_CARD | Indonesian identity card |
MYS | Malaysia | ID_CARD | Malaysian identity card |
SGP | Singapore | ID_CARD | Singapore identity card |
PHL | Philippines | PHL_UMID,PHL_VOTE_ID,PHL_TIN_ID,PHL_SSS_ID,DRIVING_LICENSE | UMID, voter's card, tax identification card, SSS social security card, driver's license |
Any country/region | - | PASSPORT | International passport |
OCR_DETECT_AUTO (automatic capture detection). Valid values:OCR_DETECT_AUTO: automatically detects the capture mode. This is the default mode.OCR_DETECT_AUTO_MANUAL: allows manual capture as a fallback if automatic capture detection fails.OCR_DETECT_AUTO_MULTI: multi-frame authentication mode. This mode is supported only for certain document types, such as Hong Kong (China) identity cards. For other document types, this value is ignored.BASIC (default) and ENHANCED (enhanced edition).import com.tencentcloudapi.common.Credential;import com.tencentcloudapi.common.profile.ClientProfile;import com.tencentcloudapi.common.profile.HttpProfile;import com.tencentcloudapi.common.exception.TencentCloudSDKException;import com.tencentcloudapi.ocr.v20181119.OcrClient;import com.tencentcloudapi.ocr.v20181119.models.*;public class ApplyOcrToken {public static void main(String[] args) {try {// Instantiate an authentication object. Input parameters need to include secretId and secretKey of the Tencent Cloud account. Keep the confidentiality of the key pair.// The key can be obtained at https://console.tencentcloud.com/cam/capi.Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"),System.getenv("TENCENTCLOUD_SECRET_KEY"));// Instantiate an HTTP option (optional). Skip it if there are no special requirements.HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint("ocr.tencentcloudapi.com");// Instantiate a client option (optional). Skip it if there are no special requirements.ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);// Instantiate the client object that requests the product. clientProfile is optional.OcrClient client = new OcrClient(cred, "ap-singapore", clientProfile);// Instantiate a request object. Each API will correspond to a request object.ApplyOcrTokenRequest req = new ApplyOcrTokenRequest();req.setNationality("HKG");req.setCardType("ID_CARD");req.setReturnHeadImage(true);// The returned resp is an instance of ApplyOcrTokenResponse, corresponding to the request object.ApplyOcrTokenResponse resp = client.ApplyOcrToken(req);// Output a string packet in JSON format.System.out.println(ApplyOcrTokenResponse.toJsonString(resp));String sdkToken = resp.getSdkToken();String encryptedConfig = resp.getEncryptedConfig();System.out.printf("SdkToken: %s, EncryptedConfig: %s", sdkToken, encryptedConfig);} catch (TencentCloudSDKException e) {System.out.println(e.toString());}}}
ResultCode field returned by this API. If ResultCode is Success, the recognition is considered successful. Otherwise, the recognition is considered failed. For details, see Common Error Codes.PROCESSING or COMPLETE.ResultCode=Success indicates that the recognition is successful.0 indicates that the authentication capability is not enabled. 1 indicates suspected forgery, such as recapture, photocopy, or PS. 2 indicates other exceptions.import com.tencentcloudapi.common.Credential;import com.tencentcloudapi.common.profile.ClientProfile;import com.tencentcloudapi.common.profile.HttpProfile;import com.tencentcloudapi.common.exception.TencentCloudSDKException;import com.tencentcloudapi.ocr.v20181119.OcrClient;import com.tencentcloudapi.ocr.v20181119.models.*;public class GetOcrVerificationResult {public static void main(String[] args) {try {// Instantiate an authentication object. Input parameters need to include secretId and secretKey of the Tencent Cloud account. Keep the confidentiality of the key pair.// The key can be obtained at https://console.tencentcloud.com/cam/capi.Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"),System.getenv("TENCENTCLOUD_SECRET_KEY"));// Instantiate an HTTP option (optional). Skip it if there are no special requirements.HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint("ocr.tencentcloudapi.com");// Instantiate a client option (optional). Skip it if there are no special requirements.ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);// Instantiate the client object that requests the product. clientProfile is optional.OcrClient client = new OcrClient(cred, "ap-singapore", clientProfile);// Instantiate a request object. Each API will correspond to a request object.GetOcrVerificationResultRequest req = new GetOcrVerificationResultRequest();req.setSdkToken("xxx"); // Enter the SdkToken returned in the ApplyOcrToken phase.// The returned resp is an instance of GetOcrVerificationResultResponse, corresponding to the request object.GetOcrVerificationResultResponse resp = client.GetOcrVerificationResult(req);// Output a string packet in JSON format.System.out.println(GetOcrVerificationResultResponse.toJsonString(resp));String status = resp.getStatus();String resultCode = resp.getResultCode();String cardInfo = resp.getCardInfo();if ("COMPLETE".equals(status) && "Success".equals(resultCode)) {// Recognition passed.System.out.println("Success");System.out.printf("CardInfo:%s", cardInfo);} else {// Recognition failed or not yet completed.System.out.printf("Status: %s, ResultCode: %s\\n", status, resultCode);}} catch (TencentCloudSDKException e) {System.out.println(e.toString());}}}
Error Code | Description |
InvalidParameterValue.InvalidParameterValueLimit | Invalid request parameter value |
InvalidParameterValue.UnsupportedCard | Unsupported country/document type combination |
AuthFailure.SignatureExpire | The SdkToken is invalid or has expired. Call ApplyOcrToken again. |
LimitExceeded.TokenRetryExhausted | The OCR call quota for this SdkToken has been exhausted. Apply for a new Token. |
FailedOperation.ResultNotReady | Recognition is not complete yet. Retry GetOcrVerificationResult later. |
RequestLimitExceeded | The request frequency exceeds the limit. Reduce the call frequency and try again. |
FailedOperation.UnknownError | An unknown error occurred within the service. Try again. |
dependencies {// Depend on the aar of Tencent Cloud OcrSDK.implementation files('libs/OcrSDK-common-model-v1.0.0-release.aar')implementation files('libs/OcrSDK-public-v2.0.0.1-release.aar')implementation files('libs/tencent-ai-sdk-aicamera-1.0.18-release.aar')implementation files('libs/tencent-ai-sdk-common-1.1.28-release.aar')implementation files("libs/tencent-ai-sdk-network-1.0.2.12-release.aar")implementation files("libs/tencent-ai-sdk-risk-oversea-1.0.0.2-release.aar")// Dependencies required by the OCR SDK to return entity objects.implementation 'com.google.code.gson:gson:2.8.9'}
<!--Camera permission--><uses-feature android:name="android.hardware.camera" /><uses-permissionandroid:name="android.permission.CAMERA"android:required="true" /><!--File storage permission [optional]--><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><!--Permission to obtain the network connection status--><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><!--Network access permission--><uses-permission android:name="android.permission.INTERNET" />
// Step 1: Initialize in the onCreate method of the Application or business page (only once).OcrOverseasCloudKit.getInstance().init(getApplicationContext());// Step 2: Before requesting the sdkToken or serverParamInfo from the business backend,// First, use createMetaData() to synchronously collect device and application metadata (encrypted inside the SDK), and submit it together with the application request.// This field remains consistent with the server-side protocol so that the backend can pass it through when calling the cloud CreateOCRToken API for risk control and parameter validation.String metaData = OcrOverseasCloudKit.getInstance().createMetaData();// TODO: Submit metaData as a request parameter (for example, with the field name metaData) to the business backend. For more information, see app-public.// Implementation of TokenApiHelper#applyToken: body.put("metaData", OcrOverseasCloudKit.getInstance().createMetaData())// Step 3: Obtain the sdkToken / serverParamInfo from the business backend.String sdkToken = "..."; // Issued by the business backend.String serverParamInfo = "..."; // Issued by the business backend as an encrypted string.// Step 4: Construct the startup configuration.OcrCloudConfig config = new OcrCloudConfig();config.setSdkToken(sdkToken);config.setServerParamInfo(serverParamInfo);config.setLanguageStyle(LanguageStyle.SIMPLIFIED_CHINESE);config.setShowPrivacyPolicyDialog(true);// Optional: Customize the UI.CustomConfigUi customConfigUi = new CustomConfigUi();customConfigUi.setShowTitleBar(true);config.setCustomConfigUi(customConfigUi);// Step 5: Start recognition.OcrOverseasCloudKit.getInstance().startCloudOcr(activity, config,new IOcrCloudResultListener() {@Overridepublic void onSuccess(OcrCloudResult result) {// After recognition is complete, the business party can use result.getSdkToken() to pull the structured result from the server.if (result.getStatus() == OcrCloudStatus.SUCCESS) {String token = result.getSdkToken();// TODO: Notify the business backend to pull the recognition result.}}@Overridepublic void onFailed(OcrCloudError error) {// Error handling: error.getErrorCode() / error.getErrorMsg()}});// Step 6: Release resources at an appropriate time (for example, in the onDestroy method of the business page).OcrOverseasCloudKit.getInstance().release();
# Keep the custom OcrSDKKit class and its members from being obfuscated.-keep class com.tencent.ocr.sdk.** {*;}# Keep third-party jar packages from being obfuscated.-keep class com.tencent.youtu.** {*;}# Do not obfuscate public library related content.-keep class com.tencent.cloud.** {*;}
// for OCR SDK"R.string.ocr_*","R.string.rst_*","R.string.net_*","R.string.msg_*",
// java 8 is supported.compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}
/*** A method for AutoSize to adapt to landscape and portrait orientations, which can be registered in the Application.* For example, with design_width_in_dp set to 360 and design_height_in_dp set to 640 (you can modify these values as needed).* <meta-data* android:name="design_width_in_dp"* android:value="360"/>* <meta-data* android:name="design_height_in_dp"* android:value="640"/>** DESIGN_WIDTH_DP = 360;* DESIGN_WIDTH_DP = 640;*/public static void addAutoSizeListener() {AutoSizeConfig.getInstance().setOnAdaptListener(new onAdaptListener() {@Overridepublic void onAdaptBefore(Object target, Activity activity) {Context context = activity;int[] currentSize = ScreenUtils.getScreenSize(context);// Set the current screen size.AutoSizeConfig.getInstance().setScreenWidth(currentSize[0]);AutoSizeConfig.getInstance().setScreenHeight(currentSize[1]);// Get the screen orientation of the current Activity.int orientation = activity.getResources().getConfiguration().orientation;// If the screen is in landscape orientation, adjust the corresponding screen baseline.if (orientation == Configuration.ORIENTATION_LANDSCAPE) {AutoSizeConfig.getInstance().setDesignWidthInDp(DESIGN_HEIGHT_DP);AutoSizeConfig.getInstance().setDesignHeightInDp(DESIGN_WIDTH_DP);} else {// If the screen is in portrait orientation, adjust the corresponding screen baseline.AutoSizeConfig.getInstance().setDesignWidthInDp(DESIGN_WIDTH_DP);AutoSizeConfig.getInstance().setDesignHeightInDp(DESIGN_HEIGHT_DP);}}@Overridepublic void onAdaptAfter(Object target, Activity activity) {}});}
├── OcrOverseasSDKKit.xcframework├── TXYRiskModuleSDK.xcframework// Resource files├── OcrModel.bundle└── OcrSDK.bundle
Info.plist:<key>Privacy - Camera Usage Description</key><string>OCR recognition requires access to your camera for identification purposes.</string>
sdkToken from its own server, and then passes the token to the SDK to start recognition. After recognition is complete, the host App uses the token to pull the final recognition result from the server. The key always remains on the server and is never delivered to the client.sdkToken, and then delivers the sdkToken and the encrypted parameter serverParamInfo to the client. When the sdkToken is obtained, you can specify whether to enable the Basic or Enhanced edition by setting the SdkVersion parameter:SdkVersion value to BASIC.SdkVersion value to ENHANCED. This edition enables the RCE capability.NSString *metaData = [OcrOverseasCloudKit createMetaData];
#import <OcrOverseasSDKKit/OcrOverseasCloudKit.h>// Initialize at an appropriate time (such as viewDidLoad)[[OcrOverseasCloudKit sharedInstance] initWithViewController:self];
#import <OcrOverseasSDKKit/OcrOverseasCloudKit.h>#import <OcrOverseasSDKKit/OcrCloudConfig.h>#import <OcrOverseasSDKKit/OcrOverseasCustomConfigUI.h>#import <OcrOverseasSDKKit/OcrCloudResult.h>#import <OcrOverseasSDKKit/OcrCloudError.h>OcrCloudConfig *cloudConfig = [[OcrCloudConfig alloc] init];// Business Token issued by the server.cloudConfig.sdkToken = @"sdkToken obtained from the server";// Encrypted parameter issued by the server.cloudConfig.serverParamInfo = @"serverParamInfo obtained from the server";// Optional: Customize the UI configuration.OcrOverseasCustomConfigUI.h *customUI = [[OcrOverseasCustomConfigUI.h alloc] init];customUI.isShowTips = YES;cloudConfig.customConfigUI = customUI;[[OcrOverseasCloudKit sharedInstance] startCloudOcr:cloudConfigwithSucceedBlock:^(OcrCloudResult *result) {// After SDK collection is complete, use result.sdkToken to pull the recognition result from the server.NSString *token = result.sdkToken;NSLog(@"Collection successful, token: %@", token);// Step 4: Use the token to request the final recognition result from the server.} withFailedBlock:^(OcrCloudError *error) {NSLog(@"Recognition failed, errorCode: %ld, errorMsg: %@", (long)error.errorCode, error.errorMsg);NSLog(@"token: %@", error.sdkToken);}];
sdkToken to call the server API to pull the final recognition result. The recognition result is returned by the server and does not pass through the client SDK.Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback