1.購(gòu)買(mǎi)接口服務(wù)
在阿里云,百度云,騰訊云等網(wǎng)站購(gòu)買(mǎi)實(shí)名認(rèn)證服務(wù)接口
以阿里云為例:
1.1網(wǎng)址:
#pic_center
1.2選購(gòu):
1.3查看使用方式:
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-520847.html
2.實(shí)現(xiàn)
2.1代碼實(shí)現(xiàn):
2.1.1工具類(lèi)下載地址: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相關(guān)依賴(lài):
//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);
//根據(jù)API的要求,定義相對(duì)應(yīng)的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返回值解釋?zhuān)?/h6>
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-520847.html
2.3轉(zhuǎn)換格式 用于返回給前端顯示認(rèn)證結(jié)果:
String result=EntityUtils.toString(response.getEntity());
// 解析成Map對(duì)象
//三個(gè)Map
//全體
Map<String,Object> responseMap = stringToJsonToMap(result);
//查詢(xún)結(jié)果
Map<String,Object> resultMap = stringToJsonToMap(String.valueOf(responseMap.get("result")));
//詳細(xì)信息
Map<String,Object> idCardInforMap = stringToJsonToMap(String.valueOf(resultMap.get("IdCardInfor")));
traverseMap(responseMap);
traverseMap(resultMap);
traverseMap(idCardInforMap);
result | 查詢(xún)結(jié)果集 |
---|---|
reason | 是否連接使用到接口 |
error_code | 返回碼 |
idcard | 身份證號(hào) |
---|---|
isok | 身份證號(hào)和姓名是否匹配 |
IdCardInfor | 詳細(xì)信息 |
realname | 真實(shí)姓名 |
IdCardInfor | |
area | 住址 |
birthday | 生日 |
province | 省份 |
city | 城市 |
district | 區(qū)域 |
sex | 性別 |
city | 城市 |
district | 區(qū)域 |
sex | 性別 |
到了這里,關(guān)于阿里云實(shí)名認(rèn)證接口的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!