公安庫聯網人臉認證、人臉識別、人證合一、刷臉認證、活體檢測
阿新 • • 發佈:2019-01-04
輸入姓名、身份證號和人臉照片(base64格式字串),對姓名和身份證號實名認證,比對公安人口庫中照片和人臉照片得到相似度得分,用於風控,人證合一校驗
public static void main(String[] args) { String host = "https://facecheck.market.alicloudapi.com"; String path = "/facecheckjson"; String method = "POST"; String appcode = "你自己的AppCode"; 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 = "{\"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); }