use of com.tencentcloudapi.ocr.v20181119.OcrClient in project Ant-Live by PinTeh.
the class TencentConfig method getOcrClient.
@Bean
public OcrClient getOcrClient() {
Credential cred = new Credential(iii, kkk);
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("ocr.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
return new OcrClient(cred, "ap-guangzhou", clientProfile);
}
use of com.tencentcloudapi.ocr.v20181119.OcrClient in project easyj by easyj-projects.
the class DefaultTencentCloudIdCardOcrServiceImpl method newOcrClient.
private OcrClient newOcrClient(TencentCloudIdCardOcrConfig config) {
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
Credential cred = this.newCredential(config);
// 实例化一个HTTP选项,可选的,没有特殊需求可以跳过
HttpProfile httpProfile = this.newHttpProfile(config);
// 实例化一个client选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = this.newClientProfile(httpProfile, config);
// 实例化要请求产品的client对象,clientProfile是可选的
return new OcrClient(cred, config.getRegion(), clientProfile);
}
use of com.tencentcloudapi.ocr.v20181119.OcrClient in project cloud-sdk by mizhousoft.
the class TencentOCRServiceImpl method init.
public void init(OCRProfile config) throws CloudSDKException {
validate(config);
Credential cred = new Credential(config.getAccessKey(), config.getSecretKey());
StsClient cosClient = new StsClient(cred, config.getRegion());
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("ocr.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
OcrClient ocrClient = new OcrClient(cred, config.getRegion(), clientProfile);
this.cosClient = cosClient;
this.ocrClient = ocrClient;
LOG.info("Init sts and ocr client successfully.");
}
use of com.tencentcloudapi.ocr.v20181119.OcrClient 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