赞
踩
华为云测试API地址:https://apiexplorer.developer.huaweicloud.com/apiexplorer/sdk?product=OCR&api=RecognizeIdCard
获取对应的参数
依赖
- <!-- 华为云sdk-->
- <dependency>
- <groupId>com.huaweicloud.sdk</groupId>
- <artifactId>huaweicloud-sdk-core</artifactId>
- <version>3.1.5</version>
- </dependency>
- <dependency>
- <groupId>com.huaweicloud.sdk</groupId>
- <artifactId>huaweicloud-sdk-ocr</artifactId>
- <version>3.1.5</version>
- </dependency>
代码
-
- /**
- *
- * @param
- * @param side 正面 反面 front:身份证正面。 back:身份证背面
- * @return
- */
- @PostMapping("/isCard")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "file", value = "身份证上传文件"),
- @ApiImplicitParam(name = "side", value = "front:身份证正面。 back:身份证背面")
- })
- public R idCard(MultipartFile file,String side) throws IOException {
-
-
-
- String ak = "3AQCOssssL";
- String sk = "MHdic08sssssh";
-
- ICredential auth = new BasicCredentials()
- .withAk(ak)
- .withSk(sk);
-
- OcrClient client = OcrClient.newBuilder()
- .withCredential(auth)
- .withRegion(OcrRegion.valueOf("cn-north-4"))
- .build();
- RecognizeIdCardRequest request = new RecognizeIdCardRequest();
- IdCardRequestBody body = new IdCardRequestBody();
- body.withDetectCopy(true); //true :返回身份证图像是否是复印件
- body.withDetectReproduce(true); //true 返回身份证图像是否经过翻拍
- body.withReturnTextLocation(true); //true 返回各个文字块区域
- body.withReturnVerification(true); //true:返回校验信息 false:不返回校验信息
- body.withSide(side); //front:身份证正面。 back:身份证背面
- body.withUrl(fileUrl); //与url二选一 图片的URL路径
- // body.withImage("s"); //图像数据,base64编码
- request.withBody(body);
- String responses = "";
- try {
- RecognizeIdCardResponse response = client.recognizeIdCard(request);
- responses = response.toString();
- System.out.println(response.toString());
- } catch (ConnectionException e) {
- e.printStackTrace();
- } catch (RequestTimeoutException e) {
- e.printStackTrace();
- } catch (ServiceResponseException e) {
- e.printStackTrace();
- System.out.println(e.getHttpStatusCode());
- System.out.println(e.getErrorCode());
- System.out.println(e.getErrorMsg());
- }
- return R.ok().data("response",responses);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。