现在很多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
希望大家搬砖快乐,有问题可留言共同讨论!