• 使用阿里云身份证扫描识别接口案例——CSDN博客


    /**
    	 * 
    	* @Title: idcard
    	* @Description: 该方法的主要作用:扫描身份证
    	* @param  @return 设定文件  
    	* @return  返回类型:String   
    	* @throws
    	 */
    	public void idcard(){
    		String host = "https://dm-51.data.aliyun.com";
    	    String path = "/rest/160601/ocr/ocr_idcard.json";
    	    String method = "POST";
    	    Map<String, String> headers = new HashMap<String, String>();
    	    headers.put("Authorization", "APPCODE " + appcode);
    	    headers.put("Content-Type", "application/json; charset=UTF-8");
    	    Map<String, String> querys = new HashMap<String, String>();
    	    String bodys = "{"inputs": [{"image": {"dataType": 50,"dataValue":""+img+""},"configure": {"dataType": 50,"dataValue":"{\"side\":\"face\"}"}}]}";
    	    try {
    	    	
    	    	HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
    	    	//System.out.println(EntityUtils.toString(response.getEntity()));
    	    	String result = EntityUtils.toString(response.getEntity());
    	    	System.out.println(result);
    	    	 JSONObject jObject =  JSONObject.fromObject(result);
    	    	 JSONArray jarray = jObject.optJSONArray("outputs");
    	    	 for (int i = 0; i < jarray.size(); i++) {
    				JSONObject subject =  jarray.getJSONObject(i);
    				String outputValue = subject.get("outputValue").toString();
    				/*outputValue={
    						  "dataType": 50,
    						  "dataValue": {
    						    "address": "山西省xxxx041",
    						    "birth": "19980908",
    						    "config_str": "{"side":"face"}",
    						    "face_rect": {
    						      "angle": -90,
    						      "center": {
    						        "x": 446,
    						        "y": 210
    						      },
    						      "size": {
    						        "height": 92,
    						        "width": 84
    						      }
    						    },
    						    "name": "xxx",
    						    "nationality": "汉",
    						    "num": "1411251998xxxxxxX",
    						    "request_id": "20170806200141_c5338b2c4fd601ea7f00c4dcc5c8ee0e",
    						    "sex": "男",
    						    "success": true
    						  }
    						}*/
    				JSONObject j_outputValue = JSONObject.fromObject(outputValue);
    				String dataValue = j_outputValue.getString("dataValue");
    				JSONObject j_dataValue = JSONObject.fromObject(dataValue);
    				customerInfo = new CustomerInfo();
    				customerInfo.setName(j_dataValue.getString("name").toString());  //姓名
    				String date = j_dataValue.getString("birth").toString();
    				customerInfo.setBorn(date);
    				SimpleDateFormat format = new SimpleDateFormat(date);
    				Date birth = format.parse(date);
    				customerInfo.setBirth(birth);//生日
    				
    				customerInfo.setAddress(j_dataValue.getString("address").toString());
    				customerInfo.setNationality(j_dataValue.getString("nationality").toString());
    				customerInfo.setNum(j_dataValue.getString("num").toString());
    				customerInfo.setSex(j_dataValue.getString("sex").toString());
    				
    			}
    	    	System.out.println(customerInfo.getName());
    	    	String jsonc = JSON.toJSONString(customerInfo);
    	    	
    			HttpServletResponse response1 = ServletActionContext.getResponse();
    			response1.setContentType("text/html;charset=utf-8");
    			PrintWriter out = response1.getWriter();
    			out.print(jsonc);
    			
    	    } catch (Exception e) {
    	    	e.printStackTrace();
    	    }
    		
    	}

  • 相关阅读:
    python多进程(二)
    PLSQL配置
    sql语句之左连结
    点击lable标出现下拉搜索框及选择功能
    angularjs前端分页自定义指令pagination
    未经整理的工作中遇到的小问题
    晒一晒工作内容.....呵呵勿喷
    配置chrome支持本地(file协议)ajax请求
    html5+angularjs+bootstrap+springmvc+mybatis模糊查询Deme
    oracle的sql积累..&..decode函数使用
  • 原文地址:https://www.cnblogs.com/a1111/p/12816205.html
Copyright © 2020-2023  润新知