当前位置:   article > 正文

调用华为云ocr身份证验证_华为云ocrjava对接身份证识别

华为云ocrjava对接身份证识别

华为云测试API地址:https://apiexplorer.developer.huaweicloud.com/apiexplorer/sdk?product=OCR&api=RecognizeIdCard

获取对应的参数

 

依赖

  1. <!-- 华为云sdk-->
  2. <dependency>
  3. <groupId>com.huaweicloud.sdk</groupId>
  4. <artifactId>huaweicloud-sdk-core</artifactId>
  5. <version>3.1.5</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>com.huaweicloud.sdk</groupId>
  9. <artifactId>huaweicloud-sdk-ocr</artifactId>
  10. <version>3.1.5</version>
  11. </dependency>

 

 代码  

  1. /**
  2. *
  3. * @param
  4. * @param side 正面 反面 front:身份证正面。 back:身份证背面
  5. * @return
  6. */
  7. @PostMapping("/isCard")
  8. @ApiImplicitParams({
  9. @ApiImplicitParam(name = "file", value = "身份证上传文件"),
  10. @ApiImplicitParam(name = "side", value = "front:身份证正面。 back:身份证背面")
  11. })
  12. public R idCard(MultipartFile file,String side) throws IOException {
  13. String ak = "3AQCOssssL";
  14. String sk = "MHdic08sssssh";
  15. ICredential auth = new BasicCredentials()
  16. .withAk(ak)
  17. .withSk(sk);
  18. OcrClient client = OcrClient.newBuilder()
  19. .withCredential(auth)
  20. .withRegion(OcrRegion.valueOf("cn-north-4"))
  21. .build();
  22. RecognizeIdCardRequest request = new RecognizeIdCardRequest();
  23. IdCardRequestBody body = new IdCardRequestBody();
  24. body.withDetectCopy(true); //true :返回身份证图像是否是复印件
  25. body.withDetectReproduce(true); //true 返回身份证图像是否经过翻拍
  26. body.withReturnTextLocation(true); //true 返回各个文字块区域
  27. body.withReturnVerification(true); //true:返回校验信息 false:不返回校验信息
  28. body.withSide(side); //front:身份证正面。 back:身份证背面
  29. body.withUrl(fileUrl); //与url二选一 图片的URL路径
  30. // body.withImage("s"); //图像数据,base64编码
  31. request.withBody(body);
  32. String responses = "";
  33. try {
  34. RecognizeIdCardResponse response = client.recognizeIdCard(request);
  35. responses = response.toString();
  36. System.out.println(response.toString());
  37. } catch (ConnectionException e) {
  38. e.printStackTrace();
  39. } catch (RequestTimeoutException e) {
  40. e.printStackTrace();
  41. } catch (ServiceResponseException e) {
  42. e.printStackTrace();
  43. System.out.println(e.getHttpStatusCode());
  44. System.out.println(e.getErrorCode());
  45. System.out.println(e.getErrorMsg());
  46. }
  47. return R.ok().data("response",responses);
  48. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/298174
推荐阅读
相关标签
  

闽ICP备14008679号