公安库联网人脸认证、人脸识别、人证合一、刷脸认证、活体检测

输入姓名、身份证号和人脸照片(base64格式字符串),对姓名和身份证号实名认证,比对公安人口库中照片和人脸照片得到相似度得分,用于风控,人证合一校验

接口地址:https://market.aliyun.com/products/57000002/cmapi024091.html#sku=yuncode1809100000

public static void main(String[] args) {
	    String host = "https://facecheck.market.alicloudapi.com";
	    String path = "/facecheckjson";
	    String method = "POST";
	    String appcode = "你自己的AppCode";
	    Map headers = new HashMap();
	    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
	    headers.put("Authorization", "APPCODE " + appcode);
	    //根据API的要求,定义相对应的Content-Type
	    headers.put("Content-Type", "application/json; charset=UTF-8");
	    Map querys = new HashMap();
	    String bodys = "{\"idCardNum\":\"身份证号\",\"realName\":\"姓名\",\"image\":\"人脸照片(纯base64字符图片小于100K)\"}";


	    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);
	    	System.out.println(response.toString());
	    	//获取response的body
	    	System.out.println(EntityUtils.toString(response.getEntity()));
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	}

     /**
     * 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
     * @param imgFilePath 图片路径
     * @return String
     */
    public static String GetImageStr(String imgFilePath) {
        byte[] data = null;
        // 读取图片字节数组
        try {
            InputStream in = new FileInputStream(imgFilePath);
            data = new byte[in.available()];
            in.read(data);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        
       // 对字节数组Base64编码
        return Base64.getEncoder().encodeToString(data);
    }

 

你可能感兴趣的:(JAVA)