|
@@ -17,6 +17,15 @@ import org.apache.http.impl.client.HttpClients;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -172,6 +181,13 @@ public class EntityAnalyse {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 营业执照识别
|
|
|
+ * @param licenseImg
|
|
|
+ * @return
|
|
|
+ * @throws ServiceException
|
|
|
+ */
|
|
|
public static DistinguishView licenseShibie(String licenseImg) throws ServiceException {
|
|
|
|
|
|
String host = "https://bizlicense.market.alicloudapi.com";
|
|
@@ -209,7 +225,316 @@ public class EntityAnalyse {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 驾驶证识别
|
|
|
+ * @param image
|
|
|
+ * @return
|
|
|
+ * @throws ServiceException
|
|
|
+ */
|
|
|
+ public static DistinguishView driverLicenseShibie(String image) throws ServiceException {
|
|
|
+
|
|
|
+ String host = "https://dm-52.data.aliyun.com";
|
|
|
+ String path = "/rest/160601/ocr/ocr_driver_license.json";
|
|
|
+ String method = "POST";
|
|
|
+ String appcode = "2d59bfa794994f5f94d1d98b7b5bd102";
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
|
|
+ headers.put("Authorization", "APPCODE " + appcode);
|
|
|
+ //根据API的要求,定义相对应的Content-Type
|
|
|
+ headers.put("Content-Type", "application/json; charset=UTF-8");
|
|
|
+ Map<String, String> querys = new HashMap<String, String>();
|
|
|
+ String bodys = "";
|
|
|
+ bodys = "{\"image\":\""+image+"\", \"configure\": {\"side\":\"face\"}}";
|
|
|
+
|
|
|
+ //阿里云APPCODE
|
|
|
+ DistinguishView distinguishView = new DistinguishView();
|
|
|
+ try {
|
|
|
+ /**
|
|
|
+ * 重要提示如下:
|
|
|
+ * HttpUtils请从
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
|
|
|
+ * 下载
|
|
|
+ *
|
|
|
+ * 相应的依赖请参照
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
|
|
+ */
|
|
|
+ HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
|
|
+ String body = EntityUtils.toString(response.getEntity());
|
|
|
+ System.out.println(body);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
+ distinguishView.setDriverEndDate(jsonObject.getString("end_date"));
|
|
|
+ String s = jsonObject.getString("vehicle_type");
|
|
|
+ if (s == "A2" || s == "B2"){
|
|
|
+ distinguishView.setAllowCar(s);
|
|
|
+ }
|
|
|
+ distinguishView.setIssuingAuthority(jsonObject.getString("issue_organization"));
|
|
|
+ return distinguishView;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 行驶证识别
|
|
|
+ * @param image
|
|
|
+ * @return
|
|
|
+ * @throws ServiceException
|
|
|
+ */
|
|
|
+ public static DistinguishView driveringLicenseShibie(String image,String flag) throws ServiceException {
|
|
|
+
|
|
|
+ String host = "https://dm-53.data.aliyun.com";
|
|
|
+ String path = "/rest/160601/ocr/ocr_vehicle.json";
|
|
|
+ String method = "POST";
|
|
|
+ String appcode = "2d59bfa794994f5f94d1d98b7b5bd102";
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
|
|
+ headers.put("Authorization", "APPCODE " + appcode);
|
|
|
+ //根据API的要求,定义相对应的Content-Type
|
|
|
+ headers.put("Content-Type", "application/json; charset=UTF-8");
|
|
|
+ Map<String, String> querys = new HashMap<String, String>();
|
|
|
+ String bodys = "";
|
|
|
+ //正面
|
|
|
+ if ("1".equals(flag)){
|
|
|
+ bodys = "{\"image\":\""+image+"\", \"configure\": {\"side\":\"face\"}}";
|
|
|
+ }
|
|
|
+ //反面
|
|
|
+ else {
|
|
|
+ bodys = "{\"image\":\""+image+"\", \"configure\": {\"side\":\"back\"}}";
|
|
|
+ }
|
|
|
|
|
|
+ //阿里云APPCODE
|
|
|
+ DistinguishView distinguishView = new DistinguishView();
|
|
|
+ try {
|
|
|
+ /**
|
|
|
+ * 重要提示如下:
|
|
|
+ * HttpUtils请从
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
|
|
|
+ * 下载
|
|
|
+ *
|
|
|
+ * 相应的依赖请参照
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
|
|
+ */
|
|
|
+ HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
|
|
+ String body = EntityUtils.toString(response.getEntity());
|
|
|
+ System.out.println(body);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
+ if("1".equals(flag)){
|
|
|
+ distinguishView.setCarNum(jsonObject.getString("plate_num"));
|
|
|
+ distinguishView.setOwner(jsonObject.getString("owner"));
|
|
|
+ String s = jsonObject.getString("register_date");
|
|
|
+ String s1 = s.substring(0,4);
|
|
|
+ String s2 = s.substring(4,6);
|
|
|
+ String s3 = s.substring(6,8);
|
|
|
+ distinguishView.setLicenseRegistrationDate(s1 + "-" + s2 + "-" + s3);
|
|
|
+ String t = jsonObject.getString("issue_date");
|
|
|
+ String t1 = t.substring(0,4);
|
|
|
+ String t2 = t.substring(4,6);
|
|
|
+ String t3 = t.substring(6,8);
|
|
|
+ distinguishView.setLicenseIssueDate(t1 + "-" + t2 + "-" + t3);
|
|
|
+ distinguishView.setLssuingAuthority(jsonObject.getString("issue_organization"));
|
|
|
+ }else {
|
|
|
+ String s = jsonObject.getString("inspection_record");
|
|
|
+ String s3 = s.substring(6,13);
|
|
|
+ String s1 = s3.replace("年","-");
|
|
|
+ distinguishView.setDriveringEndDate(s1 + "-01");
|
|
|
+ distinguishView.setDriveringNum(jsonObject.getString("file_no"));
|
|
|
+ distinguishView.setSize(jsonObject.getString("overall_dimension"));
|
|
|
+ distinguishView.setApprovedLoadMass(jsonObject.getString("approved_load"));
|
|
|
+ distinguishView.setTotalMass(jsonObject.getString("gross_mass"));
|
|
|
+ distinguishView.setServicingMass(jsonObject.getString("unladen_mass"));
|
|
|
+ }
|
|
|
+ return distinguishView;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 道路运输证证识别
|
|
|
+ * @param image
|
|
|
+ * @return
|
|
|
+ * @throws ServiceException
|
|
|
+ */
|
|
|
+ public static DistinguishView tranLicenseShibie(String image) throws ServiceException {
|
|
|
+
|
|
|
+ String host = "https://road.market.alicloudapi.com";
|
|
|
+ String path = "/ai_market/ai_ocr_universal/dao_lu_jiao_tong/v1";
|
|
|
+ String method = "POST";
|
|
|
+ String appcode = "2d59bfa794994f5f94d1d98b7b5bd102";
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
|
|
+ headers.put("Authorization", "APPCODE " + appcode);
|
|
|
+ //根据API的要求,定义相对应的Content-Type
|
|
|
+ headers.put("Content-Type", "application/json; charset=UTF-8");
|
|
|
+ Map<String, String> querys = new HashMap<String, String>();
|
|
|
+ Map<String, String> bodys = new HashMap<String, String>();
|
|
|
+ bodys.put("IMAGE", image);
|
|
|
+ bodys.put("IMAGE_TYPE", "1");
|
|
|
+
|
|
|
+ //阿里云APPCODE
|
|
|
+ DistinguishView distinguishView = new DistinguishView();
|
|
|
+ try {
|
|
|
+ /**
|
|
|
+ * 重要提示如下:
|
|
|
+ * HttpUtils请从
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
|
|
|
+ * 下载
|
|
|
+ *
|
|
|
+ * 相应的依赖请参照
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
|
|
+ */
|
|
|
+ HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
|
|
+ String body = EntityUtils.toString(response.getEntity());
|
|
|
+ System.out.println(body);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
+ distinguishView.setTranNumber(jsonObject.getJSONObject("道路运输经营许可证实体信息").getString("道路运输经营许可证编号"));
|
|
|
+ String s = jsonObject.getJSONObject("道路运输经营许可证实体信息").getString("有效期限至");
|
|
|
+ String s1 = s.replace("年","-");
|
|
|
+ String s2 = s1.replace("月","-");
|
|
|
+ String s3 = s2.replace("日","-");
|
|
|
+ distinguishView.setTranEndDate(s3);
|
|
|
+ return distinguishView;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从业资格证识别
|
|
|
+ * @param image
|
|
|
+ * @return
|
|
|
+ * @throws ServiceException
|
|
|
+ */
|
|
|
+ public static DistinguishView qualificationLicenseShibie(String image) throws ServiceException {
|
|
|
+
|
|
|
+ String host = "https://dlyzcy.market.alicloudapi.com";
|
|
|
+ String path = "/ai_ocr/dao_lu_lv_ben_lb/v1";
|
|
|
+ String method = "POST";
|
|
|
+ String appcode = "2d59bfa794994f5f94d1d98b7b5bd102";
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
|
|
+ headers.put("Authorization", "APPCODE " + appcode);
|
|
|
+ //根据API的要求,定义相对应的Content-Type
|
|
|
+ headers.put("Content-Type", "application/json; charset=UTF-8");
|
|
|
+
|
|
|
+ Map<String, String> querys = new HashMap<String, String>();
|
|
|
+ Map<String, String> bodys = new HashMap<String, String>();
|
|
|
+ bodys.put("IMAGE", image);
|
|
|
+ bodys.put("IMAGE_TYPE", "1");
|
|
|
+
|
|
|
+ //阿里云APPCODE
|
|
|
+ DistinguishView distinguishView = new DistinguishView();
|
|
|
+ try {
|
|
|
+ /**
|
|
|
+ * 重要提示如下:
|
|
|
+ * HttpUtils请从
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
|
|
|
+ * 下载
|
|
|
+ *
|
|
|
+ * 相应的依赖请参照
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
|
|
+ */
|
|
|
+ HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
|
|
+ String body = EntityUtils.toString(response.getEntity());
|
|
|
+ System.out.println(body);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
+ distinguishView.setQualificationCertificate(jsonObject.getJSONObject("智能道路运政从业人员资格证绿本版印刷文字识别实体信息").getString("有效期限"));
|
|
|
+ distinguishView.setQualificationCertificateNum(jsonObject.getJSONObject("智能道路运政从业人员资格证绿本版印刷文字识别实体信息").getString("证号"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if(distinguishView.getQualificationCertificate() == null || distinguishView.getQualificationCertificate().isEmpty()){
|
|
|
+ String host1 = "https://dlyzcy.market.alicloudapi.com";
|
|
|
+ String path1 = "/ai_ocr/dao_lu_xin_ban_new/v1";
|
|
|
+ Map<String, String> headers1 = new HashMap<String, String>();
|
|
|
+ //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
|
|
+ headers1.put("Authorization", "APPCODE " + appcode);
|
|
|
+ //根据API的要求,定义相对应的Content-Type
|
|
|
+ headers1.put("Content-Type", "application/json; charset=UTF-8");
|
|
|
+ Map<String, String> querys1 = new HashMap<String, String>();
|
|
|
+ Map<String, String> bodys1 = new HashMap<String, String>();
|
|
|
+ bodys1.put("IMAGE", image);
|
|
|
+ bodys1.put("IMAGE_TYPE", "1");
|
|
|
+
|
|
|
+ //阿里云APPCODE
|
|
|
+ DistinguishView distinguishView1 = new DistinguishView();
|
|
|
+ try {
|
|
|
+ /**
|
|
|
+ * 重要提示如下:
|
|
|
+ * HttpUtils请从
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
|
|
|
+ * 下载
|
|
|
+ *
|
|
|
+ * 相应的依赖请参照
|
|
|
+ * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
|
|
+ */
|
|
|
+ HttpResponse response = HttpUtils.doPost(host1, path1, method, headers1, querys1, bodys1);
|
|
|
+ String body = EntityUtils.toString(response.getEntity());
|
|
|
+ System.out.println(body);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
+ distinguishView1.setQualificationCertificate(jsonObject.getJSONObject("智能道路运政从业人员资格证新版印刷文字识别实体信息").getString("有效期至"));
|
|
|
+ distinguishView1.setQualificationCertificateNum(jsonObject.getJSONObject("智能道路运政从业人员资格证新版印刷文字识别实体信息").getString("从业资格证号"));
|
|
|
+ return distinguishView1;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return distinguishView;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 银行卡三要素识别
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @throws ServiceException
|
|
|
+ */
|
|
|
+ public static DistinguishView bankCradShibie(String name,String idCard,String accountNo) throws ServiceException {
|
|
|
+
|
|
|
+ String host = "https://bcard3and4.market.alicloudapi.com";
|
|
|
+ String path = "/bank3CheckNew";
|
|
|
+ String appcode = "2d59bfa794994f5f94d1d98b7b5bd102";
|
|
|
+ //阿里云APPCODE
|
|
|
+ DistinguishView distinguishView = new DistinguishView();
|
|
|
+ try {
|
|
|
+ String urlSend = host + path + "?idCard=" + idCard + "&name="+ URLEncoder.encode(name, "UTF-8") + "&accountNo="+ accountNo; //
|
|
|
+ URL url = new URL(urlSend);
|
|
|
+ HttpURLConnection httpURLCon = (HttpURLConnection) url.openConnection();
|
|
|
+ httpURLCon.setRequestProperty("Authorization", "APPCODE " + appcode);// 格式Authorization:APPCODE (中间是英文空格)
|
|
|
+ int httpCode = httpURLCon.getResponseCode();
|
|
|
+ if (httpCode == 200) {
|
|
|
+ String json = read(httpURLCon.getInputStream());
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(json);
|
|
|
+ distinguishView.setDistinguish(jsonObject.getString("msg"));
|
|
|
+ distinguishView.setDistinguishNum(jsonObject.getString("status"));
|
|
|
+ return distinguishView;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 读取返回结果
|
|
|
+ */
|
|
|
+ private static String read(InputStream is) throws IOException {
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
|
|
+ String line = null;
|
|
|
+ while ((line = br.readLine()) != null) {
|
|
|
+ line = new String(line.getBytes(), "utf-8");
|
|
|
+ sb.append(line);
|
|
|
+ }
|
|
|
+ br.close();
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
}
|