@@ -225,7 +225,7 @@ public class BaiduOcrUtil { | |||
HttpClient client = HttpClients.createDefault(); | |||
// 发送请求 | |||
HttpResponse response = sendRequest(client, url, params); | |||
; | |||
// 处理返回 无响应则重试两次 | |||
for (int i = 0; i < RETRY_TIMES; i++) { | |||
response = sendRequest(client, url, params); |
@@ -17,6 +17,9 @@ public class BusinessLicenseOcrManager extends AbstractManager { | |||
private BaiduOcrUtil baiduOcrUtil; | |||
@Autowired | |||
private ImageCompressManager imageCompressManager; | |||
private static final String BASEURL="http://100.65.10.25:8049"; | |||
public BusinessLicenseOcrResponse serviceHandle(BusinessLicenseOcrRequest req) throws ServiceHandleException { | |||
if(!StringTools.hasText(req.getUrl())){ | |||
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请传入图片地址"); | |||
@@ -26,12 +29,17 @@ public class BusinessLicenseOcrManager extends AbstractManager { | |||
public BusinessLicenseOcrResponse doBusiness(BusinessLicenseOcrRequest req) throws ServiceHandleException { | |||
try { | |||
URL url = new URL(req.getUrl()); | |||
URL downloadUrl = new URL("http", "100.65.10.25", 8049, url.getPath()); | |||
String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(downloadUrl.toString()); | |||
String reqUrl = req.getUrl(); | |||
// 判断是否为/开头 | |||
if (reqUrl.startsWith("/")) { | |||
reqUrl = BASEURL + reqUrl; | |||
}else { | |||
reqUrl = BASEURL + "/" + reqUrl; | |||
} | |||
URL url = new URL(reqUrl); | |||
String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(url.toString()); | |||
BusinessLicenseOcrResponse res = baiduOcr(compressedImgBase64); | |||
res.setImageUrl(url == null ? "" : url.toString()); | |||
res.setImageUrl(req.getUrl()); | |||
logger.info("营业执照识别结果>{}", res); | |||
return res; | |||
} catch (Exception e) { |
@@ -19,6 +19,8 @@ public class IdCardOcrManager extends AbstractManager{ | |||
@Autowired | |||
private ImageCompressManager imageCompressManager; | |||
private static final String BASEURL="http://100.65.10.25:8049"; | |||
public IdCardOcrResponse serviceHandle(IdCardOcrRequest req) throws ServiceHandleException { | |||
if(!StringTools.hasText(req.getUrl())){ | |||
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请传入图片地址"); | |||
@@ -31,12 +33,18 @@ public class IdCardOcrManager extends AbstractManager{ | |||
public IdCardOcrResponse doBusiness(IdCardOcrRequest req) throws ServiceHandleException { | |||
try { | |||
URL url = new URL(req.getUrl()); | |||
URL downloadUrl = new URL("http", "100.65.10.25", 8049, url.getPath()); | |||
String reqUrl = req.getUrl(); | |||
// 判断是否为/开头 | |||
if (reqUrl.startsWith("/")) { | |||
reqUrl = BASEURL + reqUrl; | |||
}else { | |||
reqUrl = BASEURL + "/" + reqUrl; | |||
} | |||
URL url = new URL(reqUrl); | |||
String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(downloadUrl.toString()); | |||
String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(url.toString()); | |||
IdCardOcrResponse res = baiduOcr(compressedImgBase64, req.getImageType()); | |||
res.setImageUrl(url == null ? "" : url.toString()); | |||
res.setImageUrl(req.getUrl()); | |||
logger.info("身份证识别结果>{}", res); | |||
return res; | |||
} catch (Exception e) { |
@@ -18,6 +18,8 @@ public class VehicleLicenseOcrManager extends AbstractManager { | |||
@Autowired | |||
private ImageCompressManager imageCompressManager; | |||
private static final String BASEURL="http://100.65.10.25:8049"; | |||
public VehicleLicenseOcrResponse serviceHandle(VehicleLicenseOcrRequest req) throws ServiceHandleException { | |||
if(!StringTools.hasText(req.getUrl())){ | |||
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请传入图片地址"); | |||
@@ -30,12 +32,18 @@ public class VehicleLicenseOcrManager extends AbstractManager { | |||
public VehicleLicenseOcrResponse doBusiness(VehicleLicenseOcrRequest req) throws ServiceHandleException { | |||
try { | |||
URL url = new URL(req.getUrl()); | |||
URL downloadUrl = new URL("http", "100.65.10.25", 8049, url.getPath()); | |||
String reqUrl = req.getUrl(); | |||
// 判断是否为/开头 | |||
if (reqUrl.startsWith("/")) { | |||
reqUrl = BASEURL + reqUrl; | |||
}else { | |||
reqUrl = BASEURL + "/" + reqUrl; | |||
} | |||
URL url = new URL(reqUrl); | |||
String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(downloadUrl.toString()); | |||
String compressedImgBase64 = imageCompressManager.getBaiduOcrCompressBase64(url.toString()); | |||
VehicleLicenseOcrResponse res = baiduOcr(compressedImgBase64, req.getImageType()); | |||
res.setImageUrl(url == null ? "" : url.toString()); | |||
res.setImageUrl(req.getUrl()); | |||
logger.info("驾驶证识别结果>{}", res); | |||
return res; | |||
} catch (Exception e) { |