java实现身份证实名认证(调用阿里云api)
!!这个接口调用了公安接口 进行验证 不是普通的身份证号码验证.可以识别身份证号码生成器
阿里api市场链接:
https://market.aliyun.com/products/56928004/cmapi016424.html?spm=5176.2020520132.101.9.VRsLss#sku=yuncode10424000011
复制Appcode
package ali;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class aliyun {
/**
* requestGet
* @param strUrl
* @param param
* @param appcode
* @return
*/
public static String requestGet(String strUrl, String param, String appcode) {
String returnStr = null; // 返回结果定义
URL url = null;
HttpURLConnection httpURLConnection = null;
try {
url = new URL(strUrl + "?" + param);
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestProperty("Accept-Charset", "utf-8");
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpURLConnection.setRequestProperty("Authorization", "APPCODE " + appcode);
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("GET"); // get方式
httpURLConnection.setUseCaches(false); // 不用缓存
httpURLConnection.connect();
BufferedReader reader = new BufferedReader(
new InputStreamReader(httpURLConnection.getInputStream(), "utf-8"));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
reader.close();
returnStr = buffer.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
}
return returnStr;
}
/**
* return
* @param args
*/
public static void main(String[] args) {
//请正确填写appcode,如果填写错误阿里云会返回错误
//appcode查看地址 https://market.console.aliyun.com/imageconsole/
String appcode = "您的appcode";
//请求地址
String url="http://1.api.apistore.cn/idcard";
//需要请求的内容
String param="cardNo=身份证号码&realName=姓名";
//执行请求
String returnStr=aliyun.requestGet(url, param, appcode);
//输出结果
System.out.println(returnStr);
}
}
成功图片演示