package api.jisuapi.drivinglicenserecognition; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import Decoder.BASE64Encoder; import api.util.HttpUtil; import net.sf.json.JSONObject; public class Recognize { public static final String APPKEY = "your_appkey_here";// 你的appkey public static final String URL = "https://api.jisuapi.com/drivinglicenserecognition/recognize"; public static final String pic = "11.jpg";// 图片地址 public static void Get() { String result = null; String url = URL + "?appkey=" + APPKEY; Mapparam = new HashMap (); try { param.put("pic", getBase64(pic)); result = HttpUtil.sendPost(url, param, "UTF-8"); JSONObject json = JSONObject.fromObject(result); if (json.getInt("status") != 0) { System.out.println(json.getString("msg")); } else { JSONObject resultarr = (JSONObject) json.opt("result"); String lsprefix = resultarr.getString("lsprefix"); String lsnum = resultarr.getString("lsnum"); String lstype = resultarr.getString("lstype"); String lstypename = resultarr.getString("lstypename"); String realname = resultarr.getString("realname"); String address = resultarr.getString("address"); String cartype = resultarr.getString("cartype"); String frameno = resultarr.getString("frameno"); String engineno = resultarr.getString("engineno"); String regdate = resultarr.getString("regdate"); String issuedate = resultarr.getString("issuedate"); String usetype = resultarr.getString("usetype"); System.out.println(lsprefix + " " + lsnum + " " + lstype + " " + lstypename + " " + realname + " " + address + " " + cartype + " " + frameno + " " + engineno + " " + regdate + " " + issuedate + " " + usetype); } } catch (Exception e) { e.printStackTrace(); } } /** * 图片转为Base64编码格式 * * @param imgFile * @return */ public static String getBase64(String imgFile) { InputStream inputStream = null; byte[] data = null; try { inputStream = new FileInputStream(imgFile); data = new byte[inputStream.available()]; inputStream.read(data); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } // 加密 BASE64Encoder encoder = new BASE64Encoder(); return encoder.encode(data); } }
© 2015-2024 杭州极速互联科技有限公司 版权所有 浙ICP备17047587号-4 浙公网安备33010502005096 增值电信业务经营许可证:浙B2-20190875