1.购买接口服务
在阿里云,百度云,腾讯云等网站购买实名认证服务接口
以阿里云为例:
1.1网址:
![在这里插入图片描述](https://img-blog.csdnimg.cn/img_convert/24802ec646a98a921cdde6383c573f69.png#pic_center
1.2选购:
1.3查看使用方式:
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
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.15</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.3.7.v20160115</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
</dependencies>
public static void main(String[] args) {
String host = "https://zid.market.alicloudapi.com";
String path = "/idcheck/Post";
String method = "POST";
String appcode = "ab68c2e9dbc04b37a27dc514c8fd4612";
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "APPCODE " + appcode);
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("cardNo", "xxxxxxxxxxxxxxxxxx");
bodys.put("realName", "xxx");
try {
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
System.out.println(response.toString());
System.out.println(EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}
2.2返回值解释:
2.3转换格式 用于返回给前端显示认证结果:
String result=EntityUtils.toString(response.getEntity());
Map<String,Object> responseMap = stringToJsonToMap(result);
Map<String,Object> resultMap = stringToJsonToMap(String.valueOf(responseMap.get("result")));
Map<String,Object> idCardInforMap = stringToJsonToMap(String.valueOf(resultMap.get("IdCardInfor")));
traverseMap(responseMap);
traverseMap(resultMap);
traverseMap(idCardInforMap);
result | 查询结果集 |
---|
reason | 是否连接使用到接口 | error_code | 返回码 |
idcard | 身份证号 |
---|
isok | 身份证号和姓名是否匹配 | IdCardInfor | 详细信息 | realname | 真实姓名 | IdCardInfor | | area | 住址 | birthday | 生日 | province | 省份 | city | 城市 | district | 区域 | sex | 性别 | city | 城市 | district | 区域 | sex | 性别 |
|