腾讯云卡证识别

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_39443053/article/details/102690466

腾讯云卡证识别

          点关注不迷路,欢迎再访!

腾讯云卡证识别:https://cloud.tencent.com/document/product/866/33524

现在是公测阶段,正式收费2020/01/01

1.首先去注册账号,新建密钥,生成APPID,SecretId,SecretKey,在调用接口是需要绑定参数。
在这里插入图片描述

调用官方接口有API/SDK两种方式,本章我们采用SDK 3.0来实现:

github源码地址:https://github.com/TencentCloud/tencentcloud-sdk-java

2.首先引入依赖

<dependency>
	        <groupId>com.tencentcloudapi</groupId>
	        <artifactId>tencentcloud-sdk-java</artifactId>   
	        <version>3.0.67</version>
        </dependency>

3.编写身份证测试类

/**
	 * imageData :图片
	 * type :0正面,反面
*/
public String idcardDetect(byte[] imageData, int type) throws Exception {
		 String result="";
	     try{
	    	String cardSide = "";
	    	if(type==0) {
	    		cardSide="FRONT";
	    	}else {
	    		cardSide="BACK";
	    	}
            Credential cred = new Credential(secretId, secretKey);	            
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("ocr.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);            	            
            OcrClient client = new OcrClient(cred, "ap-shanghai", clientProfile);
            String params = "{\"ImageBase64\":\""+Base64Util.encode(imageData)+"\",\"CardSide\":\""+cardSide+"\"}";
            IDCardOCRRequest req = IDCardOCRRequest.fromJsonString(params, IDCardOCRRequest.class);	            
            IDCardOCRResponse resp = client.IDCardOCR(req);
            result = IDCardOCRRequest.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
        	return e.getMessage();
        }
		return result;
	}

4.需要去开通对应服务才可以访问:

{“code”:3,“message”:“服务未开通,请在控制台开通服务。”,“seq”:“0b49f66f-cccc-4fe5-b6cc-20f4cea4ac58”,“data”:{}
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_39443053/article/details/102690466