現在很多APP為何確定用戶信息都需要進行身份證實名認證,但是一般的實名認證有很大的可能性是用戶填寫的他人的身份證信息,為了確保操作人和所填寫的身份證信息為同一人,阿里雲有款接口可以進行人臉與身份證頭像的比對接口,確保人證合一,很大程度上保證了操作人的真實性。
首先用戶先填寫身份證信息,APP調用攝像頭采集人臉信息;然后將采集到的頭像進行BASE64編碼(需要URLEncoder.encode,防止亂碼),將三者信息上送至阿里雲的核驗接口進行比對返回是否匹配的結果,即:(姓名、身份證號碼、人臉照片編碼)。
拋送接口的代碼(這里以java版展示,產品頁面中間的文檔有其他語言版本的):
public static void main(String[] args) { String host = "https://idfaceauth.market.alicloudapi.com"; String path = "/idFaceAuthenticate"; String method = "POST"; String appcode = "你自己的AppCode"; //購買服務成功后在控制台查看自己的秘鑰 Map<String, String> headers = new HashMap<String, String>(); //最后在header中的格式(中間是英文空格)為Authorization:APPCODE 83359fd73fe949483856870e3c139105 headers.put("Authorization", "APPCODE " + appcode); //根據API的要求,定義相對應的Content-Type headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); Map<String, String> querys = new HashMap<String, String>(); Map<String, String> bodys = new HashMap<String, String>(); bodys.put("idNo", "340421199922225555"); bodys.put("name", "張三"); bodys.put("photoStr", "data:image/jpg;base64,/9j/4AAQSkZJRgABAQAA... ...3F/9k=");//人臉照片編碼base64后的字符串 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(); } }
返回的處理結果實例:
{ "name": "張三", "idNo": "340421199710045202", "respMessage": "身份證號與姓名匹配,照片為同一人", "respCode": "R0000", "province": "安徽省", "city": "淮南市", "county": "鳳台縣", "birthday": "19871004", "sex": "M", "age": "24" }
具體詳細可以在產品頁面查看:https://market.aliyun.com/products/57000002/cmapi00047889.html?#sku=yuncode4188900001
希望大家搬磚快樂,有問題可留言共同討論!