아 리 운 OCR - 신분증 / 영업 허가증 식별
아 리 클 라 우 드 AccessKeyId 와 AccessKeySecret 를 만 듭 니 다.구체 적 으로 는 AccessKey 생 성 을 참조 하 십시오.자바 의존 설치.구체 적 으로 자바 의존 설치 참조.프로젝트 프로젝트 에 Extension. Uploader 도구 류 를 다운로드 하고 도입 합 니 다.
공식 문서:
신분증 정보
@RequestMapping(value = "/idCardInfo")
@ResponseBody
public Object idCardInfo(MultipartFile idcardFront) throws ClientException {
IClientProfile profile = DefaultProfile
.getProfile("cn-shanghai", " accessKeyId", " accessKeySecret");
DefaultProfile
.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
IAcsClient client = new DefaultAcsClient(profile);
ImageSyncScanRequest imageSyncScanRequest = new ImageSyncScanRequest();
// api
imageSyncScanRequest.setAcceptFormat(FormatType.JSON);
//
imageSyncScanRequest.setMethod(MethodType.POST);
imageSyncScanRequest.setEncoding("utf-8");
// http https
imageSyncScanRequest.setProtocol(ProtocolType.HTTP);
JSONObject httpBody = new JSONObject();
/**
*
* ocr: ocr ocr
*/
httpBody.put("scenes", Arrays.asList("ocr"));
/**
* , task, 100 , 100 task
* , 。 rt , ,rt
* , , task
* , ,
*/
ClientUploader clientUploader = ClientUploader.getImageClientUploader(profile, false);
byte[] imageBytes = null;
String url = null;
try{
// , ,
//imageBytes = FileUtils.readFileToByteArray();
//
url = clientUploader.uploadBytes(idcardFront.getBytes());
}catch (Exception e){
System.out.println("upload file to server fail.");
}
JSONObject task = new JSONObject();
task.put("dataId", UUID.randomUUID().toString());
task.put("url", url);
task.put("time", new Date());
httpBody.put("tasks", Arrays.asList(task));
//ocr ,
JSONObject cardExtras = new JSONObject();
//
cardExtras.put("card", "id-card-front");
//
//cardExtras.put("card", "id-card-back");
httpBody.put("extras", cardExtras);
imageSyncScanRequest.setHttpContent(org.apache.commons.codec.binary.StringUtils.getBytesUtf8(httpBody.toJSONString()), "UTF-8", FormatType.JSON);
/**
* , 10 ,
* ReadTimeout , read timeout
*/
imageSyncScanRequest.setConnectTimeout(3000);
imageSyncScanRequest.setReadTimeout(10000);
HttpResponse httpResponse = null;
try {
httpResponse = client.doAction(imageSyncScanRequest);
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
Map<String, Object> map = new HashMap<String, Object>();
// ,
if(httpResponse != null && httpResponse.isSuccess()){
JSONObject scrResponse = JSON.parseObject(org.apache.commons.codec.binary.StringUtils.newStringUtf8(httpResponse.getHttpContent()));
//System.out.println(JSON.toJSONString(scrResponse));
int requestCode = scrResponse.getIntValue("code");
//
JSONArray taskResults = scrResponse.getJSONArray("data");
if (200 == requestCode) {
for (Object taskResult : taskResults) {
//
int taskCode = ((JSONObject)taskResult).getIntValue("code");
// , ,
JSONArray sceneResults = ((JSONObject)taskResult).getJSONArray("results");
if(200 == taskCode){
for (Object sceneResult : sceneResults) {
String scene = ((JSONObject)sceneResult).getString("scene");
String suggestion = ((JSONObject)sceneResult).getString("suggestion");
//do something
//
if("review" .equals(suggestion) && "ocr".equals(scene)){
JSONObject idCardInfo = ((JSONObject) sceneResult).getJSONObject("idCardInfo");
// System.out.println(idCardInfo.toJSONString());
map.put("name", idCardInfo.get("name"));
map.put("number", idCardInfo.get("number"));
}
}
}else{
// ,
//System.out.println("task process fail. task response:" + JSON.toJSONString(taskResult));
map.put("error","task process fail. task response:" + JSON.toJSONString(taskResult));
}
}
} else {
/**
* ,
*/
//System.out.println("the whole image scan request failed. response:" + JSON.toJSONString(scrResponse));
map.put("error", "the whole image scan request failed. response:" + JSON.toJSONString(scrResponse));
}
}
return map;
}
영업 허가증
@RequestMapping(value = "/businessLicenseInfo")
@ResponseBody
public Object businessLicenseInfo(MultipartFile file) throws ClientException {
IClientProfile profile = DefaultProfile
.getProfile("cn-shanghai", " accessKeyId", " accessKeySecret");
DefaultProfile
.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
IAcsClient client = new DefaultAcsClient(profile);
ImageSyncScanRequest imageSyncScanRequest = new ImageSyncScanRequest();
// api
imageSyncScanRequest.setAcceptFormat(FormatType.JSON);
//
imageSyncScanRequest.setMethod(MethodType.POST);
imageSyncScanRequest.setEncoding("utf-8");
// http https
imageSyncScanRequest.setProtocol(ProtocolType.HTTP);
JSONObject httpBody = new JSONObject();
/**
*
* ocr: ocr ocr
*/
httpBody.put("scenes", Arrays.asList("ocr"));
/**
* , task, 100 , 100 task
* , 。 rt , ,rt
* , , task
* , ,
*/
ClientUploader clientUploader = ClientUploader.getImageClientUploader(profile, false);
byte[] imageBytes = null;
String url = null;
try{
// , ,
//imageBytes = FileUtils.readFileToByteArray((File) file);
//
url = clientUploader.uploadBytes(file.getBytes());
}catch (Exception e){
System.out.println("upload file to server fail.");
}
JSONObject task = new JSONObject();
task.put("dataId", UUID.randomUUID().toString());
task.put("url", url);
task.put("time", new Date());
httpBody.put("tasks", Arrays.asList(task));
//ocr ,
JSONObject cardExtras = new JSONObject();
// :
cardExtras.put("card", "business-license");
httpBody.put("extras", cardExtras);
imageSyncScanRequest.setHttpContent(org.apache.commons.codec.binary.StringUtils.getBytesUtf8(httpBody.toJSONString()), "UTF-8", FormatType.JSON);
/**
* , 10 ,
* ReadTimeout , read timeout
*/
imageSyncScanRequest.setConnectTimeout(3000);
imageSyncScanRequest.setReadTimeout(10000);
HttpResponse httpResponse = null;
try {
httpResponse = client.doAction(imageSyncScanRequest);
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
Map<String, Object> map = new HashMap<String, Object>();
// ,
if(httpResponse != null && httpResponse.isSuccess()){
JSONObject scrResponse = JSON.parseObject(org.apache.commons.codec.binary.StringUtils.newStringUtf8(httpResponse.getHttpContent()));
//System.out.println(JSON.toJSONString(scrResponse));
int requestCode = scrResponse.getIntValue("code");
//
JSONArray taskResults = scrResponse.getJSONArray("data");
if (200 == requestCode) {
for (Object taskResult : taskResults) {
//
int taskCode = ((JSONObject)taskResult).getIntValue("code");
// , ,
JSONArray sceneResults = ((JSONObject)taskResult).getJSONArray("results");
if(200 == taskCode){
for (Object sceneResult : sceneResults) {
String scene = ((JSONObject)sceneResult).getString("scene");
String suggestion = ((JSONObject)sceneResult).getString("suggestion");
//do something
//
if("review" .equals(suggestion) && "ocr".equals(scene)){
JSONObject businessLicenseInfo = ((JSONObject) sceneResult).getJSONObject("businessLicenseInfo");
System.out.println(businessLicenseInfo.toJSONString());
map.put("regNum", businessLicenseInfo.get("regNum"));
}
}
}else{
// ,
//System.out.println("task process fail. task response:" + JSON.toJSONString(taskResult));
map.put("error","task process fail. task response:" + JSON.toJSONString(taskResult));
}
}
} else {
/**
* ,
*/
//System.out.println("the whole image scan request failed. response:" + JSON.toJSONString(scrResponse));
map.put("error", "the whole image scan request failed. response:" + JSON.toJSONString(scrResponse));
}
}
return map;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.