Search in sources :

Example 1 with OcrClient

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);
}
Also used : Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) OcrClient(com.tencentcloudapi.ocr.v20181119.OcrClient) Bean(org.springframework.context.annotation.Bean)

Example 2 with OcrClient

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);
}
Also used : Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) OcrClient(com.tencentcloudapi.ocr.v20181119.OcrClient)

Example 3 with OcrClient

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.");
}
Also used : StsClient(com.tencentcloudapi.sts.v20180813.StsClient) TempCredential(com.mizhousoft.cloudsdk.TempCredential) Credential(com.tencentcloudapi.common.Credential) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) OcrClient(com.tencentcloudapi.ocr.v20181119.OcrClient)

Example 4 with OcrClient

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;
    }
}
Also used : TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) OcrClient(com.tencentcloudapi.ocr.v20181119.OcrClient) IDCardOCRResponse(com.tencentcloudapi.ocr.v20181119.models.IDCardOCRResponse)

Aggregations

OcrClient (com.tencentcloudapi.ocr.v20181119.OcrClient)4 Credential (com.tencentcloudapi.common.Credential)3 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)3 HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)3 TempCredential (com.mizhousoft.cloudsdk.TempCredential)1 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)1 IDCardOCRResponse (com.tencentcloudapi.ocr.v20181119.models.IDCardOCRResponse)1 StsClient (com.tencentcloudapi.sts.v20180813.StsClient)1 Bean (org.springframework.context.annotation.Bean)1