1.购买接口服务
在阿里云,百度云,腾讯云等网站购买实名认证服务接口
以阿里云为例:
1.1网址:
![在这里插入图片描述](https://img-blog.csdnimg.cn/img_convert/24802ec646a98a921cdde6383c573f69.png#pic_center
1.2选购:
![7jRlP1.png](https://img-blog.csdnimg.cn/img_convert/f7a8b435ebd691e7e01d160424c72f3a.png)
1.3查看使用方式:
![7jRKa9.png](https://img-blog.csdnimg.cn/img_convert/f33c1c63e9f42b0f9e08245446dd348d.png)
2.实现
2.1代码实现:
2.1.1工具类下载地址:https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
2.2.2相关依赖:
//https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
com.alibaba
fastjson
1.2.15
org.apache.httpcomponents
httpclient
4.2.1
org.apache.httpcomponents
httpcore
4.2.1
commons-lang
commons-lang
2.6
org.eclipse.jetty
jetty-util
9.3.7.v20160115
junit
junit
4.5
test
com.fasterxml.jackson.core
jackson-databind
2.9.8
public static void main(String[] args) {
String host = "https://zid.market.alicloudapi.com";
String path = "/idcheck/Post";
String method = "POST";
String appcode = "ab68c2e9dbc04b37a27dc514c8fd4612";
Map headers = new HashMap();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + appcode);
//根据API的要求,定义相对应的Content-Type
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Map querys = new HashMap();
Map bodys = new HashMap();
bodys.put("cardNo", "xxxxxxxxxxxxxxxxxx");
bodys.put("realName", "xxx");
try {
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();
}
}
2.2返回值解释:
![7jRM5R.png](https://img-blog.csdnimg.cn/img_convert/545569e199e87963547253e0f07b4ee4.png)
2.3转换格式 用于返回给前端显示认证结果:
String result=EntityUtils.toString(response.getEntity());
// 解析成Map对象
//三个Map
//全体
Map responseMap = stringToJsonToMap(result);
//查询结果
Map resultMap = stringToJsonToMap(String.valueOf(responseMap.get("result")));
//详细信息
Map idCardInforMap = stringToJsonToMap(String.valueOf(resultMap.get("IdCardInfor")));
traverseMap(responseMap);
traverseMap(resultMap);
traverseMap(idCardInforMap);
result查询结果集reason是否连接使用到接口error_code返回码
idcard身份证号isok身份证号和姓名是否匹配IdCardInfor详细信息realname真实姓名IdCardInforarea住址birthday生日province省份city城市district区域sex性别city城市district区域sex性别
|