|
|
@ -31,6 +31,7 @@ public class BaiDuUtil { |
|
|
|
private static final String GENERAL_BASIC_URL = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token={}"; |
|
|
|
/**通用文字识别(高精度版)*/ |
|
|
|
private static final String ACCURATE_BASIC_URL = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token={}"; |
|
|
|
private static final String VAT_INVOICE = "https://aip.baidubce.com/rest/2.0/ocr/v1/vat_invoice?access_token={}"; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init(){ |
|
|
@ -112,6 +113,37 @@ public class BaiDuUtil { |
|
|
|
return getGeneralBasic(appKey, secretKey, basic, GENERAL_BASIC_URL); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 调用百度增值税发票识别 |
|
|
|
* @param appKey appKey |
|
|
|
* @param secretKey secretKey |
|
|
|
* @param basic 图像 |
|
|
|
* @return 识别结果 |
|
|
|
*/ |
|
|
|
public static BaiDuVo.BillBasic billBasic(String appKey, String secretKey, BaiDuDto.GeneralBasic basic) { |
|
|
|
return getBillBasic(appKey, secretKey, basic, VAT_INVOICE); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 增值税发票识别 |
|
|
|
* @param appKey appKey |
|
|
|
* @param secretKey secretKey |
|
|
|
* @param basic 图像 |
|
|
|
* @param accurateBasicUrl 路径 |
|
|
|
* @return 识别结果 |
|
|
|
*/ |
|
|
|
private static BaiDuVo.BillBasic getBillBasic(String appKey, String secretKey, BaiDuDto.GeneralBasic basic, String accurateBasicUrl) { |
|
|
|
String token = getToken(appKey, secretKey); |
|
|
|
String url = StrUtil.format(accurateBasicUrl, token); |
|
|
|
String result = RestTemplateUtil.postUrlEncode(url, basic); |
|
|
|
log.info("百度orc调用{}的结果是:{}", url, result); |
|
|
|
if (result.contains(Code.GENERAL_BASIC_ERROR)) { |
|
|
|
CodeEnum thirdError = CodeEnum.THIRD_ERROR; |
|
|
|
thirdError.setMsg(result); |
|
|
|
throw new BaseException(thirdError); |
|
|
|
} |
|
|
|
return JSONObject.parseObject(result, BaiDuVo.BillBasic.class); |
|
|
|
} |
|
|
|
|
|
|
|
private static class Code{ |
|
|
|
private final static String ERROR = "error"; |
|
|
|
private final static String GENERAL_BASIC_ERROR = "error_code"; |
|
|
|