采用的是聚合网站的接口。json解析用的Gson库。下载地址:http://download.csdn.net/detail/bjq1016/8225447

两个JavaBean:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.itfanr.IDCard;
/**
 * Created by itfanr on 14/12/4.
 */
public class ResultInfo {
    private int resultcode ;
    private  String reason ;
    public Person getResult() {
        return result;
    }
    public void setResult(Person result) {
        this.result = result;
    }
    private Person result ;
    private int error_code ;
    public int getResultcode() {
        return resultcode;
    }
    public void setResultcode(int resultcode) {
        this.resultcode = resultcode;
    }
    public String getReason() {
        return reason;
    }
    public void setReason(String reason) {
        this.reason = reason;
    }
    public int getError_code() {
        return error_code;
    }
    public void setError_code(int error_code) {
        this.error_code = error_code;
    }
  public String toString(){
      return "ResutltInfo-> ""resultcode: "this.getResultcode()
              +" reason: "+this.getReason()+"\n"+"result: "this.getResult()
              +"\n"+"error_code: "this.getError_code() ;
  }
}

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.itfanr.IDCard;
/**
 * Created by itfanr on 14/12/4.
 */
public class Person {
    private String area ;
    private String sex ;
    private  String birthday ;
    private String verify;
    public String getVerify() {
        return verify;
    }
    public void setVerify(String verify) {
        this.verify = verify;
    }
    public String getArea() {
        return area;
    }
    public void setArea(String area) {
        this.area = area;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public String getBirthday() {
        return birthday;
    }
    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }
    public String toString(){
        return "Person info-> ""area: "this.getArea()
                " birthday: " this.getBirthday()
                +" sex: "this.getSex() + " verify: "+this.getVerify();
    }
}

查询类,get方式请求数据:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.itfanr.IDCard;
/**
 * Created by itfanr on 14/12/4.
 */
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL ;
import  java.net.HttpURLConnection ;
public class Search {
    private String key ;
    public Search(String key ) {
        this.key =key ;
    }
    public  String seatchID(String id){
        String url = "http://apis.juhe.cn/idcard/index?key="+this.key+ "&cardno="+ id ;
        URL urlNet = null ;
        InputStream is = null ;
        ByteArrayOutputStream bao = null ;
        String result = null ;
        try {
            urlNet = new URL(url);
            try {
                HttpURLConnection conn = (HttpURLConnection)urlNet.openConnection() ;
                conn.setReadTimeout(5*1000 );
                conn.setRequestMethod("GET");
                 is = conn.getInputStream() ;
                int len = -1 ;
                byte[] buf = new byte[128] ;
                bao = new ByteArrayOutputStream() ;
                while ((len = is.read(buf))!=-1){
                    bao.write(buf,0,len);
                }
                bao.flush();
                result = new String(bao.toByteArray()) ;
            catch (IOException e) {
                e.printStackTrace();
            }
        catch (MalformedURLException e) {
            e.printStackTrace();
        }finally {
            if (is!=null){
                try {
                    is.close();
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (bao!=null){
                try {
                    bao.close();
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result ;
    }
}

测试类:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.itfanr.IDCard;
/**
 * Created by itfanr on 14/11/23.
 */
import  com.google.gson.Gson ;
public class Test {
    public  static void  main(String args[]){
        Search s = new Search("your_key" ) ;
        String result = s.seatchID("330326198903081211");
        Gson gson = new Gson() ;
        ResultInfo resultInfo  = gson.fromJson(result, ResultInfo.class);
        ;
        System.out.println(resultInfo);
    }
}

输出结果:

?
1
2
3
ResutltInfo-> resultcode: 203 reason: 身份证校验位不正确
result: Person info-> area: 浙江省温州市平阳县 birthday: 19890308日 sex: 男 verify: 该身份证号校验位不正确
error_code: 203803

java实现身份证归属地查询相关推荐

  1. 身份证归属地查询软件(离线版)

    这是一款使用C#语言写的软件,可以实现身份证归属地离线查询功能,目前源代码已经开源至码云,github平台,效果如下: 当输入前两位数字时,可查询到相关省:当输入前四位数字时,可查询到相关市:当输入前 ...

  2. java手机号归属地查询_【原创】Java实现手机号码归属地查询

    网络上已经有很多的手机号码归属地查询的API接口,但是这些接口总是有一些大大小小的缺陷. 总结一下这些缺陷: 1.要直接将它的搜索框链接形式粘到自己的页面,点击查询的时候还要跳转到他们的网站来展示归属 ...

  3. java 手机号码归属地_【原创】Java实现手机号码归属地查询

    网络上已经有很多的手机号码归属地查询的API接口,但是这些接口总是有一些大大小小的缺陷. 总结一下这些缺陷: 1.要直接将它的搜索框链接形式粘到自己的页面,点击查询的时候还要跳转到他们的网站来展示归属 ...

  4. 【原创】Java实现手机号码归属地查询

    网络上已经有很多的手机号码归属地查询的API接口,但是这些接口总是有一些大大小小的缺陷. 总结一下这些缺陷: 1.要直接将它的搜索框链接形式粘到自己的页面,点击查询的时候还要跳转到他们的网站来展示归属 ...

  5. Java百宝箱——实现ip地址、手机号、身份证号归属地查询

    文章目录 1.功能界面 2.ip地址查询 3.身份证归属地查询 4.更多查询 1.功能界面 package com.company;import com.alibaba.fastjson.JSONOb ...

  6. .net函数查询_Java百宝箱——实现ip地址、手机号、身份证号归属地查询

    文章目录 1.功能界面 2.ip地址查询 3.身份证归属地查询 4.更多功能(简繁体转换.天气查询) 网上冲浪是我们每个人每天必做的运动 ,那么在冲浪时,每个人都会携带一个ip地址.电影中的黑客往往能 ...

  7. python 身份证归属地解析

    浏览器抓包114身份证查询网站得知身份证归属地查询实际地址为:http://tool.114la.com/static/js/area.js 复制到txt后将整个文本改成一个大list,用python ...

  8. Java实现IP库归属地查询

    一.IP库文件下载,各产品对比 二.IP库的实现有很多种,我这里采用的是GeoIP2 Jar 包依赖引入 下载好IP库文件 代码实现 运行结果 三.工程代码下载 参考文章 一.IP库文件下载,各产品对 ...

  9. java 手机号归属地查询

    根据手机号码查询归属地.运营商我们引用google的libphonenumber包,libphonenumber是用于解析.格式化.存储和校验电话号码的Java.C++或JavaScript类库. 依 ...

  10. java如何获取手机号码归属地_在java中如何根据手机号查询号码归属地

    在java中如何根据手机号查询号码归属地 1.maven项目中配置 com.googlecode.libphonenumber geocoder 2.15 com.googlecode.libphon ...

最新文章

  1. andorid 启动模式面试题
  2. 一致性哈希(Consistent Hashing)
  3. 3D视觉应用开发--机器人3D互动四大技术难点分析
  4. 超级干货丨优美的课程笔记,吴恩达点赞的深度学习课程信息图
  5. python从入门到精通学习笔记_Python从入门到精通之基础概念
  6. 从零单排学Redis【铂金一】
  7. 中国象棋程序的设计与实现(五)--回答CSDN读者的一些问题
  8. WP Rocket插件无需授权版本
  9. 数学与计算机科学学院宣传词,【榜样人物】筑梦前行 不负韶华——数学与计算机科学学院姚彬彬同学的考研心路...
  10. 制作Camtasia 2020击键标记动画
  11. vc10的C2664和C2065错误
  12. 在线画图工具ProcessOn
  13. [IMX6DL][Android4.4] 超声波模块HC-SR04 Linux驱动源代码
  14. 中小板企业上市要走哪些流程
  15. Matplotlib绘制半圆形
  16. 【加密算法】凯撒密码的原理及Python实现
  17. Flutter水波纹效果
  18. IT-RS-IPV6-EUI-64
  19. Mysql的主键和索引
  20. 112-smart-toc-2021-09-09

热门文章

  1. java微信聊天机器人源码_三步轻松打造微信聊天机器人(附源码)
  2. matlab模拟厄米高斯光束,拉盖尔高斯光束_厄米高斯光束MATLAB仿真.pdf
  3. Linux cJSON
  4. 光猫超级账号密码、宽带账号密码 获取
  5. 中国地区城市php,中国城市列表
  6. 汽车诊断协议 - CAN BUS协议
  7. USTC高级软件工程课程学习心得
  8. CSDN博客专家证书发放名单(10月已更新)
  9. clickhouse各种表引擎的异同
  10. 刚体运动学公式_经典运动学公式汇总