描写叙述 :依据身份证编号 查询归属地信息。

身份证实体类:

package org.wx.xhelper.model;

/**
* 身份证实体类
* @author wangxw
* @version 1.0
* @date Jul 11, 2014 10:46:54 AM
*/
public class IdCard { // 身份证号码
private String idCard; // 出生日期
private String born; // 性别
private String sex; // 所在地区
private String att; public String getIdCard() {
return idCard;
} public void setIdCard(String idCard) {
this.idCard = idCard;
} public String getBorn() {
return born;
} public void setBorn(String born) {
this.born = born;
} public String getSex() {
return sex;
} public void setSex(String sex) {
this.sex = sex;
} public String getAtt() {
return att;
} public void setAtt(String att) {
this.att = att;
} }

服务接口类:

package org.wx.xhelper.service;

import java.io.UnsupportedEncodingException;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.wx.xhelper.model.IdCard; /**
* 身份证信息服务接口类
* @author wangxw
* @version 1.0
* @date Jul 11, 2014 10:49:57 AM
*/
public class IdCardService { /**
* 生成身份证信息
* @param cardNo
* @return 返回身份证信息
* @throws UnsupportedEncodingException
*/
public static String getIdCardDetail(String cardNo) throws UnsupportedEncodingException{
// 获取身份证信息
IdCard idcard = getIdCardInfo(cardNo); // 存储文本信息
StringBuffer news = new StringBuffer(); if (idcard != null) {
news.append("所属地区:"+idcard.getAtt()).append("\n");
news.append("出生日期:"+idcard.getBorn()).append("\n");
news.append("性别:"+idcard.getSex()).append("\n");
} if(news.length() == 0){
news.append("身份证号码").append(cardNo).append("不存在,请又一次输入!");
} return news.toString();
} /**
* 获取身份证信息
* @param cardNo
* @return 返回身份证信息
*/
public static IdCard getIdCardInfo(String cardNo){
URL url = null;
IdCard idCard = new IdCard();
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder(); url = new URL("http://api.k780.com:88/? app=idcard.get&idcard="+cardNo+"&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=xml"); System.out.println(url); Document doc = builder.parse(url.openStream());
NodeList node = doc.getElementsByTagName("result"); for(int i=0;i<node.getLength();i++){
String idcard = "";
String born = "";
String sex = "";
String att = "";
if(doc.getElementsByTagName("idcard").item(i).getFirstChild() != null){
idcard = doc.getElementsByTagName("idcard").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("born").item(i).getFirstChild() != null){
born = doc.getElementsByTagName("born").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("sex").item(i).getFirstChild() != null){
sex = doc.getElementsByTagName("sex").item(i).getFirstChild().getNodeValue();
}
if(doc.getElementsByTagName("att").item(i).getFirstChild() != null){
att = doc.getElementsByTagName("att").item(i).getFirstChild().getNodeValue();
}
idCard.setIdCard(idcard);
idCard.setBorn(born);
idCard.setSex(sex);
idCard.setAtt(att);
} }catch(Exception e){
e.printStackTrace();
}
return idCard;
} public static void main(String[] args){
try {
System.out.print(getIdCardDetail("110101199001011118"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} }

返回结果:

所属地区:北京市东城区

出生日期:1990年01月01日

性别:男

身份证归属地查询免费api接口代码的更多相关文章

  1. 手机号码归属地查询免费api接口代码

    依据手机号码查询用户的卡类型.运营商.归属地.区域等信息. 手机归属地实体类 package org.wx.xhelper.model; /** * 手机归属地 * @author wangxw * ...

  2. 身份证归属地查询免费api接口

    描写叙述 :依据身份证编号 查询归属地信息. 调用地址: http://api.k780.com:88/? app=idcard.get&idcard=510103195309280011&a ...

  3. 违章查询免费api接口代码

    能够依据城市+车牌号+发动机号查询违章信息列表. 违章实体类 package org.wx.xhelper.model; /** * 违章实体类 * @author wangxw * @version ...

  4. 快递单号查询免费api接口(PHP示例)

    快递单号查询API,可以对接顺丰快递查询,邮政快递查询,中通快递查询等.这些快递物流企业,提供了快递单号自动识别接口,快递单号查询接口等快递物流服务.对于电商企业,ERP服务企业,集成此接口到自己的软 ...

  5. 公交线路免费api接口代码

    描写叙述:本接口主要是依据城市名称 +  线路名称 模糊查找城市公交线路信息. 开源api接口:http://openapi.aibang.com/bus/lines?app_key=keyvalue ...

  6. 各类无次数限制的免费API接口整理

    各类无次数限制的免费API接口整理,主要是聚合数据上和API Store上的一些,还有一些其他的. 聚合数据提供30大类,160种以上基础数据API服务,国内最大的基础数据API服务,下面就罗列一些免 ...

  7. 网络免费API接口整理

    转载自: https://www.cnblogs.com/doit8791/p/9351629.html 从网上看到一些免费API接口,在个人开发小程序等应用练手时可试用. 各类无次数限制的免费API ...

  8. 各类无次数限制的免费API接口,再也不怕找不到免费API了

    各类无次数限制的免费API接口整理,主要是聚合数据上和API Store上的一些,还有一些其他的. 聚合数据提供30大类,160种以上基础数据API服务,国内最大的基础数据API服务,下面就罗列一些免 ...

  9. 免费API接口记录

    用来记录一些无次数限制的免费API接口,主要是聚合数据上和API Store上的一些,还有一些其他的. 手机号码归属地API接口: https://www.juhe.cn/docs/api/id/11 ...

随机推荐

  1. 洛谷 [P2341] 受欢迎的牛

    强连通分量 一个结论: 在有向图中, 一个联通块能被所有点遍历当且仅当图中只有一个连通块出度为零 #include <iostream> #include <cstdio> # ...

  2. .net web api ioc unity usage

    1.use nuget to install unity.webapi 2.add configurations in application_start folder using Microsoft ...

  3. Python学习杂记_5_列表常用操作

    列表操作 列表时用方括号括起来的一组元素值,是可变变量,可通过下表取值,也可以通过下表来修改值,列表中的元素是有序的,可以是不同的基本数据类型,如: names=[1, 2, 3, “abc”, “d ...

  4. 误加all_load引起的程序报错

    一.为什么要加-all_load 在64位的mac系统和iOS系统下,链接器有一个bug,会导致只包含有类别的静态库无法使用-ObjC标志来加载文件.解决方法是使用-all_load或者-force_ ...

  5. 前端js、jQuery实现日期格式化、字符串格式化

    1. js仿后台的字符串的StringFormat方法 在做前端页面时候,经常会对字符串进行拼接处理,但是直接使用字符串拼接,不但影响阅读,而且影响执行效率,且jQuery有没有定义字符串的Strin ...

  6. CSU 1997: Seating Arrangement【构造】

    1997: Seating Arrangement Description Mr. Teacher老师班上一共有n个同学,编号为1到n. 在上课的时候Mr. Teacher要求同学们从左至右按1, 2 ...

  7. [转载]robo3t在Ubuntu 16.04中报错的解决方法

    [问题] MongoDB的客户端robo3t在,Ubuntu 16.04中启动时报一个QT的错误: This application failed to start because it could ...

  8. 【ActiveMQ】消息生产者自动注入报错:Could not autowire. No beans of 'JmsMessagingTemplate' type found

    使用ActiveMQ过程中,定义消息生产者: package com.sxd.jms.producer; import org.springframework.beans.factory.annota ...

  9. hibernate多对一单向配置

    查看:http://blog.csdn.net/u010702229/article/details/13170263

  10. php从数据库选取记录形成列表(首页调用)

    <ul class="e1"> <?php $querySel = "select ID,Tit,Addtime from news where DSh ...