1.购买接口服务
在阿里云,百度云,腾讯云等网站购买实名认证服务接口
以阿里云为例:
1.1网址:
#pic_center
1.2选购:
1.3查看使用方式:
文章来源:https://www.toymoban.com/news/detail-520847.html
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>();
//最后在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<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());
//获取response的body
System.out.println(EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}
2.2返回值解释:
文章来源地址https://www.toymoban.com/news/detail-520847.html
2.3转换格式 用于返回给前端显示认证结果:
String result=EntityUtils.toString(response.getEntity());
// 解析成Map对象
//三个Map
//全体
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 | 性别 |
到了这里,关于阿里云实名认证接口的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!