java实现身份证实名认证(阿里云api)

java实现身份证实名认证(调用阿里云api)

!!这个接口调用了公安接口 进行验证 不是普通的身份证号码验证.可以识别身份证号码生成器
阿里api市场链接:
https://market.aliyun.com/products/56928004/cmapi016424.html?spm=5176.2020520132.101.9.VRsLss#sku=yuncode10424000011
java实现身份证实名认证(阿里云api)_第1张图片
复制Appcode
java实现身份证实名认证(阿里云api)_第2张图片

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);
    }

}


成功图片演示
java实现身份证实名认证(阿里云api)_第3张图片


身份证号码生成器链接:
http://www.welefen.com/lab/identify?province=%E9%BB%91%E9%BE%99%E6%B1%9F&city=%E9%BB%91%E6%B2%B3%E5%B8%82&area=%E5%8C%97%E5%AE%89%E5%B8%82&year=1950&month=1&day=1&sex=%E7%94%B7

你可能感兴趣的:(阿里API,java身份证,身份识别,身份证)