use of com.tencentcloudapi.ocr.v20181119.models.IDCardOCRResponse in project easyj by easyj-projects.
the class DefaultTencentCloudIdCardOcrServiceImpl method doIdCardOcr.
// region Override start
// //region 身份证识别 start
/**
* 身份证识别
*
* @param request 请求
* @param config 当前请求的个性配置
* @return response 响应
* @see <a href="https://cloud.tencent.com/document/api/866/33524">API文档</a>
* @see <a href="https://console.cloud.tencent.com/api/explorer?Product=ocr&Version=2018-11-19&Action=IDCardOCR">调试页面</a>
*/
@Override
public IDCardOCRResponse doIdCardOcr(IDCardOCRRequest request, @Nullable TencentCloudIdCardOcrConfig config) throws TencentCloudSDKException {
if (config == null) {
config = this.globalConfig;
}
Assert.notNull(config.getSecretId(), "'secretId' must not be null");
Assert.notNull(config.getSecretKey(), "'secretKey' must not be null");
Assert.notNull(config.getRegion(), "'region' must not be null");
long startTime = System.nanoTime();
try {
// 实例化要请求产品的client对象,clientProfile是可选的
OcrClient client;
if (config == this.globalConfig) {
client = this.globalClient;
} else {
client = this.newOcrClient(config);
}
// 发送请求,并返回一个IDCardOCRResponse的实例,与请求对象对应
IDCardOCRResponse response = client.IDCardOCR(request);
// 记录日志
if (LOGGER.isInfoEnabled()) {
// base64不打印在日志中
String imageBase64Bak = request.getImageBase64();
String advancedInfoBak = response.getAdvancedInfo();
request.setImageBase64(null);
response.setAdvancedInfo(null);
try {
LOGGER.info("IDCardOCR 请求成功!\r\n==>\r\n - Request: {}\r\n - Response: {}\r\n - Config: {}\r\n - Cost: {} ms\r\n<==\r\n", icu.easyj.core.util.StringUtils.toString(request), icu.easyj.core.util.StringUtils.toString(response), icu.easyj.core.util.StringUtils.toString(config), (System.nanoTime() - startTime) / 1000000);
} finally {
request.setImageBase64(imageBase64Bak);
response.setAdvancedInfo(advancedInfoBak);
}
}
return response;
} catch (TencentCloudSDKException | RuntimeException e) {
String imageBase64Bak = request.getImageBase64();
// base64不打印在日志中
request.setImageBase64(null);
try {
LOGGER.error("身份证识别服务请求失败:{}\r\n==>\r\n - Request: {}\r\n - Config: {}\r\n - Cost: {} ms\r\n<==\r\n", e.getMessage(), icu.easyj.core.util.StringUtils.toString(request), icu.easyj.core.util.StringUtils.toString(config), (System.nanoTime() - startTime) / 1000000);
} finally {
request.setImageBase64(imageBase64Bak);
}
throw e;
}
}
Aggregations