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

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

}


成功图片演示
这里写图片描述


身份证号码生成器链接:
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

评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值