小米官网发货要多久六6月1号官网有没有发货的

4336人阅读
Android笔记(74)
  在这里,我所使用的是网易有道的接口,把网址/smartresult-xml/search.s?type=id&q= + 要查询的身份证号,粘贴到浏览器上打开,可以看到返回的是一个表示结果的XML文件。目前未发现使用限制。
  首先在浏览器 上测试一个有效的身份证号,查看源文件,可以看到返回的信息中,有四个元素是我们需要的,即code身份证号码,location身份证发证地,birthday生日,gender性别。再试一下查询无效的身份证号,只有一个&smartresult/&。
  创建一个类,表示身份证信息,内容如下(get及set方法省略),为方便测试,还得覆写toString方法,将所有内容打印出来:
public class IdCard {
  然后从网上下载查询返回的结果,并判断该身份证号是否有效。在前面的,已经知道如果查询不到身份证信息,将返回&smartresult /&,否则,返回的是&smartresult& 身份证详细内容&/smartresult&。实现的代码如下:
* 根据身份证号查询相关信息。
* @param id
public IdCard query(String id) {
String info =
info = getStringFromUrl(
&/smartresult-xml/search.s?type=id&q=&
+ id, &gbk&);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
if ( info == null || info.contains(&&smartresult/&&)) {
System.out.println(info);
IdCard idCard = parseXML(info);
System.out.println(idCard);
return idC
  该方法接收一个表示身份证号的字符串,与查询地址拼接,然后获取该地址的数据,如果返回的是null指针,表示无法下载到数据,如果返回的数据库包含了&smartresult/&标签,则说明查询不到结果。在上面的代码中,由于自己只需要查询到身份证号码的结果的情况并进行进一步的操作,所对将另两种作一起判断,返回空指针。这个亦可在if语句中分别判断并给出不同的提示。getStringFromUrl是自己写的一个方法,共有两个参数,第一个表示请求的网址,第二个表示编码格式。该方法实现也比较简单,内容如下:
* 根据URL名得到输入流。
* @param urlStr
* @return 得到的输入流。
* @throws MalformedURLException
如果字符串指定未知协议。
* @throws IOException
如果发生 I/O 错误。
private String getStringFromUrl(String urlStr, String charsetName) throws MalformedURLException, IOException {
URL url = new URL(urlStr);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
InputStream in = urlConn.getInputStream();
String string = InputStreamToString(in, charsetName);
在上面的方法中,得到的是InputStream类型的对象,还需要转换成String类型。这个可以在网上找,代码如下:
* 将InputStream转换成String
* @param urlStr
* @param charsetName
private String InputStreamToString ( InputStream in, String charsetName) {
if (in == null) {
StringBuilder sb = new StringBuilder();
String temp =
BufferedReader bf = new BufferedReader(new InputStreamReader(in, charsetName));
while ((temp = bf.readLine()) != null) {
sb.append(temp).append(&\n&);
} catch (IOException e) {
e.printStackTrace();
return sb.toString();
  到这里,我们已经能得到一个String类型的结果了。下面将对这个结果进行解析。由于内容较简单,也可对结果用正则表示式提取数据。我这里用到的是XMLReader类,来解析XML文件。用这种方法,需要实现ContentHandler接口。下面的代码中,是通过继承DefaultHandler类并重写里面的方法来实现的。
public class MyContentHandler extends DefaultHandler {
private IdCard idC
private String tagN
public MyContentHandler(IdCard idCard) {
this.idCard = idC
public void characters(char[] ch, int start, int length)
throws SAXException {
String tmp = new String(ch, start, length);
if (tagName.equals(&code&)) {
idCard.setId(tmp);
} else if (tagName.equals(&location&)) {
idCard.setLocation(tmp);
} else if (tagName.equals(&birthday&)) {
idCard.setBirthYear(tmp.substring(0, 4));
idCard.setBirthMonth(tmp.substring(4, 6));
idCard.setBirthDay(tmp.substring(6, 8));
} else if (tagName.equals(&gender&)) {
idCard.setGender(tmp);
public void endDocument() throws SAXException {
super.endDocument();
public void endElement(String uri, String localName, String qName)
throws SAXException {
tagName = &&;
public void startDocument() throws SAXException {
super.startDocument();
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
this.tagName = localN
if (&&.equals(localName)) {
this.tagName = qN
System.out.println(&uri:& + uri + &, localName:& + localName + &, qName:& + qName);
public IdCard getIdCard() {
return idC
  上面的代码可能还不完善。其中的成员变量tagName,是为了对读到的元素进行标记。关于这段代码,可以参数mars-droid第一季视频中XML文件那一集。在这里其中在startElement方法中,我对tagName的赋值是这样的:
this.tagName = localN
if (&&.equals(localName)) {
this.tagName = qN
  看起来貌似很麻烦。这个也是我一时想到的。我在使用的时候悲剧地发现,第一次使用时读到的如code等元素,是赋值在qName中的,但是移植到Android中时,貌似却是读到localName的,又不知它会不会变成赋值到qName中去,只好用这个方法了。
  实现了ContentHandler之后,下面对其使用的代码如下:
* 得析得到的XML字符串的信息
* @param info
private IdCard parseXML(String info) {
IdCard idCard = new IdCard();
XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
MyContentHandler contentHandler = new MyContentHandler(idCard);
xmlReader.setContentHandler(contentHandler);
xmlReader.parse(new InputSource(new StringReader(info)));
} catch (Exception e) {
e.printStackTrace();
return idC
 这样就得到了IdCard对象了。
  以上内容中,如果有问题,或有更好的实现方法,还望大家指教。我是菜鸟。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1685124次
积分:12356
积分:12356
排名:第970名
原创:127篇
译文:74篇
评论:798条
Android高级开发群:
Andriod Studio Tech:
文章:21篇
阅读:142572
文章:53篇
阅读:106262
文章:25篇
阅读:260561
(2)(8)(1)(1)(2)(6)(1)(1)(4)(1)(4)(4)(2)(5)(6)(1)(1)(4)(4)(4)(9)(4)(4)(1)(9)(13)(21)(5)(5)(4)(14)(4)(7)(7)(6)(2)(5)(2)(8)(8)(3)
微信关注我的公众号怎么用java后台获取读卡器读取到的身份证信息_java吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:608,764贴子:
怎么用java后台获取读卡器读取到的身份证信息收藏
山穷水尽啦 给我一个方向也行啊
JSR80你看看呗
厂家会提供接口或者插件的
你用的读卡器是华视还是华旭还是其他的?
难道没给你java调用的接口?
屁,扫描枪读会员卡biu的一下自己就出来了。如何读取都要用java实现的话要读卡器厂家干屁呀?错了请轻喷
撸主解决问题没
难道身份证信息都不加密的么?            --一条很长的小尾巴--
卤煮,可以给我发个 神思的接口吗
楼主,现在我也要做这么个需求。B/S架构,jsp页面获取usb身份读卡器读取身份证信息?请问你之前怎么实现的啊?急求。。。
把你那身份证数据接口调用的发我一份吧,邮箱
同求,楼主好人 谢谢给我也发一份吧
没找到接口在哪,目前就给我了个android和ios相关代码,同求身份证数据接口调用,,楼主好人!!!!!!!
同求,楼主好人,麻烦给我也发一份吧
非常感谢!
楼主啊~可怜可怜小弟给我发一份
楼主是好人
亲,也给我发一份吧,邮箱,二次开发的java版sdk和如何调用,谢啦!
跟厂家要接口代码,厂家会给你接口代码的
,跪求楼主分享一下JSP页面通过身份证扫描仪获取身份证信息的调用接口,谢谢
,跪求楼主分享一下JSP页面通过身份证扫描仪获取身份证信息的调用接口,谢谢!!!!!!!!!!
急需啊 ~~~楼主给我份吧谢谢了
楼主给个思路啊
楼主在不,能否指导一下怎么查信息啊
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或8729人阅读
JavaSE(17)
程序员必须要有一个好的思想,代码有时候就体现了一个人的灵魂,所以理解需求比技术更重要!
IdcardValidator类
import java.text.ParseE
import java.text.SimpleDateF
import java.util.C
import java.util.D
import java.util.GregorianC
import java.util.regex.P
public class IdcardValidator {
* 省,直辖市代码表: { 11:&北京&,12:&天津&,13:&河北&,14:&山西&,15:&内蒙古&,
* 21:&辽宁&,22:&吉林&,23:&黑龙江&,31:&上海&,32:&江苏&,
* 33:&浙江&,34:&安徽&,35:&福建&,36:&江西&,37:&山东&,41:&河南&,
* 42:&湖北&,43:&湖南&,44:&广东&,45:&广西&,46:&海南&,50:&重庆&,
* 51:&四川&,52:&贵州&,53:&云南&,54:&西藏&,61:&陕西&,62:&甘肃&,
* 63:&青海&,64:&宁夏&,65:&新疆&,71:&台湾&,81:&香港&,82:&澳门&,91:&国外&}
protected String codeAndCity[][] = { { &11&, &北京& }, { &12&, &天津& },
{ &13&, &河北& }, { &14&, &山西& }, { &15&, &内蒙古& }, { &21&, &辽宁& },
{ &22&, &吉林& }, { &23&, &黑龙江& }, { &31&, &上海& }, { &32&, &江苏& },
{ &33&, &浙江& }, { &34&, &安徽& }, { &35&, &福建& }, { &36&, &江西& },
{ &37&, &山东& }, { &41&, &河南& }, { &42&, &湖北& }, { &43&, &湖南& },
{ &44&, &广东& }, { &45&, &广西& }, { &46&, &海南& }, { &50&, &重庆& },
{ &51&, &四川& }, { &52&, &贵州& }, { &53&, &云南& }, { &54&, &西藏& },
{ &61&, &陕西& }, { &62&, &甘肃& }, { &63&, &青海& }, { &64&, &宁夏& },
{ &65&, &新疆& }, { &71&, &台湾& }, { &81&, &香港& }, { &82&, &澳门& },
{ &91&, &国外& } };
private String cityCode[] = { &11&, &12&, &13&, &14&, &15&, &21&, &22&,
&23&, &31&, &32&, &33&, &34&, &35&, &36&, &37&, &41&, &42&, &43&,
&44&, &45&, &46&, &50&, &51&, &52&, &53&, &54&, &61&, &62&, &63&,
&64&, &65&, &71&, &81&, &82&, &91& };
// 每位加权因子
private int power[] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
// 第18位校检码
private String verifyCode[] = { &1&, &0&, &X&, &9&, &8&, &7&, &6&, &5&,
&4&, &3&, &2& };
* 验证所有的身份证的合法性
* @param idcard
public boolean isValidatedAllIdcard(String idcard) {
if (idcard.length() == 15) {
idcard = this.convertIdcarBy15bit(idcard);
return this.isValidate18Idcard(idcard);
* 判断18位身份证的合法性
* 根据〖中华人民共和国国家标准GB〗中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本体码和一位数字校验码组成。
* 排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码。
* 顺序码: 表示在同一地址码所标识的区域范围内,对同年、同月、同 日出生的人编定的顺序号,顺序码的奇数分配给男性,偶数分配 给女性。
* 1.前1、2位数字表示:所在省份的代码; 2.第3、4位数字表示:所在城市的代码; 3.第5、6位数字表示:所在区县的代码;
* 4.第7~14位数字表示:出生年、月、日; 5.第15、16位数字表示:所在地的派出所的代码;
* 6.第17位数字表示性别:奇数表示男性,偶数表示女性;
* 7.第18位数字是校检码:也有的说是个人信息码,一般是随计算机的随机产生,用来检验身份证的正确性。校检码可以是0~9的数字,有时也用x表示。
* 第十八位数字(校验码)的计算方法为: 1.将前面的身份证号码17位数分别乘以不同的系数。从第一位到第十七位的系数分别为:7 9 10 5 8 4
* 2 1 6 3 7 9 10 5 8 4 2
* 2.将这17位数字和系数相乘的结果相加。
* 3.用加出来和除以11,看余数是多少?
* 4.余数只可能有0 1 2 3 4 5 6 7 8 9 10这11个数字。其分别对应的最后一位身份证的号码为1 0 X 9 8 7 6 5 4 3
* 5.通过上面得知如果余数是2,就会在身份证的第18位数字上出现罗马数字的Ⅹ。如果余数是10,身份证的最后一位号码就是2。
* @param idcard
public boolean isValidate18Idcard(String idcard) {
// 非18位为假
if (idcard.length() != 18) {
// 获取前17位
String idcard17 = idcard.substring(0, 17);
// 获取第18位
String idcard18Code = idcard.substring(17, 18);
char c[] =
String checkCode = &&;
// 是否都为数字
if (isDigital(idcard17)) {
c = idcard17.toCharArray();
if (null != c) {
int bit[] = new int[idcard17.length()];
bit = converCharToInt(c);
int sum17 = 0;
sum17 = getPowerSum(bit);
// 将和值与11取模得到余数进行校验码判断
checkCode = getCheckCodeBySum(sum17);
if (null == checkCode) {
// 将身份证的第18位与算出来的校码进行匹配,不相等就为假
if (!idcard18Code.equalsIgnoreCase(checkCode)) {
* 验证15位身份证的合法性,该方法验证不准确,最好是将15转为18位后再判断,该类中已提供。
* @param idcard
public boolean isValidate15Idcard(String idcard) {
// 非15位为假
if (idcard.length() != 15) {
// 是否全都为数字
if (isDigital(idcard)) {
String provinceid = idcard.substring(0, 2);
String birthday = idcard.substring(6, 12);
int year = Integer.parseInt(idcard.substring(6, 8));
int month = Integer.parseInt(idcard.substring(8, 10));
int day = Integer.parseInt(idcard.substring(10, 12));
// 判断是否为合法的省份
boolean flag =
for (String id : cityCode) {
if (id.equals(provinceid)) {
if (!flag) {
// 该身份证生出日期在当前日期之后时为假
Date birthdate =
birthdate = new SimpleDateFormat(&yyMMdd&).parse(birthday);
} catch (ParseException e) {
e.printStackTrace();
if (birthdate == null || new Date().before(birthdate)) {
// 判断是否为合法的年份
GregorianCalendar curDay = new GregorianCalendar();
int curYear = curDay.get(Calendar.YEAR);
int year2bit = Integer.parseInt(String.valueOf(curYear)
.substring(2));
// 判断该年份的两位表示法,小于50的和大于当前年份的,为假
if ((year & 50 && year & year2bit)) {
// 判断是否为合法的月份
if (month & 1 || month & 12) {
// 判断是否为合法的日期
boolean mflag =
curDay.setTime(birthdate); // 将该身份证的出生日期赋于对象curDay
switch (month) {
mflag = (day &= 1 && day &= 31);
case 2: // 公历的2月非闰年有28天,闰年的2月是29天。
if (curDay.isLeapYear(curDay.get(Calendar.YEAR))) {
mflag = (day &= 1 && day &= 29);
mflag = (day &= 1 && day &= 28);
mflag = (day &= 1 && day &= 30);
if (!mflag) {
* 将15位的身份证转成18位身份证
* @param idcard
public String convertIdcarBy15bit(String idcard) {
String idcard17 =
// 非15位身份证
if (idcard.length() != 15) {
if (isDigital(idcard)) {
// 获取出生年月日
String birthday = idcard.substring(6, 12);
Date birthdate =
birthdate = new SimpleDateFormat(&yyMMdd&).parse(birthday);
} catch (ParseException e) {
e.printStackTrace();
Calendar cday = Calendar.getInstance();
cday.setTime(birthdate);
String year = String.valueOf(cday.get(Calendar.YEAR));
idcard17 = idcard.substring(0, 6) + year + idcard.substring(8);
char c[] = idcard17.toCharArray();
String checkCode = &&;
if (null != c) {
int bit[] = new int[idcard17.length()];
// 将字符数组转为整型数组
bit = converCharToInt(c);
int sum17 = 0;
sum17 = getPowerSum(bit);
// 获取和值与11取模得到余数进行校验码
checkCode = getCheckCodeBySum(sum17);
// 获取不到校验位
if (null == checkCode) {
// 将前17位与第18位校验码拼接
idcard17 += checkC
} else { // 身份证包含数字
return idcard17;
* 15位和18位身份证号码的基本数字和位数验校
* @param idcard
public boolean isIdcard(String idcard) {
return idcard == null || &&.equals(idcard) ? false : Pattern.matches(
&(^\\d{15}$)|(\\d{17}(?:\\d|x|X)$)&, idcard);
* 15位身份证号码的基本数字和位数验校
* @param idcard
public boolean is15Idcard(String idcard) {
return idcard == null || &&.equals(idcard) ? false : Pattern.matches(
&^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$&,
* 18位身份证号码的基本数字和位数验校
* @param idcard
public boolean is18Idcard(String idcard) {
return Pattern
&^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([\\d|x|X]{1})$&,
* 数字验证
* @param str
public boolean isDigital(String str) {
return str == null || &&.equals(str) ? false : str.matches(&^[0-9]*$&);
* 将身份证的每位和对应位的加权因子相乘之后,再得到和值
* @param bit
public int getPowerSum(int[] bit) {
int sum = 0;
if (power.length != bit.length) {
for (int i = 0; i & bit. i++) {
for (int j = 0; j & power. j++) {
if (i == j) {
sum = sum + bit[i] * power[j];
* 将和值与11取模得到余数进行校验码判断
* @param checkCode
* @param sum17
* @return 校验位
public String getCheckCodeBySum(int sum17) {
String checkCode =
switch (sum17 % 11) {
checkCode = &2&;
checkCode = &3&;
checkCode = &4&;
checkCode = &5&;
checkCode = &6&;
checkCode = &7&;
checkCode = &8&;
checkCode = &9&;
checkCode = &x&;
checkCode = &0&;
checkCode = &1&;
return checkC
* 将字符数组转为整型数组
* @param c
* @throws NumberFormatException
public int[] converCharToInt(char[] c) throws NumberFormatException {
int[] a = new int[c.length];
int k = 0;
for (char temp : c) {
a[k++] = Integer.parseInt(String.valueOf(temp));
public static void main(String[] args) throws Exception {
String idcard15 = &&;
String idcard18 = &&;
IdcardValidator iv = new IdcardValidator();
boolean flag =
flag = iv.isValidate18Idcard(idcard18);
System.out.println(flag);
flag = iv.isValidate15Idcard(idcard15);
System.out.println(flag);
System.out.println(iv.convertIdcarBy15bit(idcard15));
flag = iv.isValidate18Idcard(iv.convertIdcarBy15bit(idcard15));
System.out.println(flag);
System.out.println(iv.isValidatedAllIdcard(idcard18));
IdcardInfoExtractor类:
import java.text.SimpleDateF
import java.util.C
import java.util.D
import java.util.GregorianC
import java.util.HashM
import java.util.M
import java.util.S
public class IdcardInfoExtractor {
// 出生日期
private Map&String, String& cityCodeMap = new HashMap&String, String&() {
this.put(&11&, &北京&);
this.put(&12&, &天津&);
this.put(&13&, &河北&);
this.put(&14&, &山西&);
this.put(&15&, &内蒙古&);
this.put(&21&, &辽宁&);
this.put(&22&, &吉林&);
this.put(&23&, &黑龙江&);
this.put(&31&, &上海&);
this.put(&32&, &江苏&);
this.put(&33&, &浙江&);
this.put(&34&, &安徽&);
this.put(&35&, &福建&);
this.put(&36&, &江西&);
this.put(&37&, &山东&);
this.put(&41&, &河南&);
this.put(&42&, &湖北&);
this.put(&43&, &湖南&);
this.put(&44&, &广东&);
this.put(&45&, &广西&);
this.put(&46&, &海南&);
this.put(&50&, &重庆&);
this.put(&51&, &四川&);
this.put(&52&, &贵州&);
this.put(&53&, &云南&);
this.put(&54&, &西藏&);
this.put(&61&, &陕西&);
this.put(&62&, &甘肃&);
this.put(&63&, &青海&);
this.put(&64&, &宁夏&);
this.put(&65&, &新疆&);
this.put(&71&, &台湾&);
this.put(&81&, &香港&);
this.put(&82&, &澳门&);
this.put(&91&, &国外&);
private IdcardValidator validator =
* 通过构造方法初始化各个成员属性
public IdcardInfoExtractor(String idcard) {
validator = new IdcardValidator();
if (validator.isValidatedAllIdcard(idcard)) {
if (idcard.length() == 15) {
idcard = validator.convertIdcarBy15bit(idcard);
// 获取省份
String provinceId = idcard.substring(0, 2);
Set&String& key = this.cityCodeMap.keySet();
for (String id : key) {
if (id.equals(provinceId)) {
this.province = this.cityCodeMap.get(id);
// 获取性别
String id17 = idcard.substring(16, 17);
if (Integer.parseInt(id17) % 2 != 0) {
this.gender = &男&;
this.gender = &女&;
// 获取出生日期
String birthday = idcard.substring(6, 14);
Date birthdate = new SimpleDateFormat(&yyyyMMdd&)
.parse(birthday);
this.birthday =
GregorianCalendar currentDay = new GregorianCalendar();
currentDay.setTime(birthdate);
this.year = currentDay.get(Calendar.YEAR);
this.month = currentDay.get(Calendar.MONTH) + 1;
this.day = currentDay.get(Calendar.DAY_OF_MONTH);
//获取年龄
SimpleDateFormat simpleDateFormat=new SimpleDateFormat(&yyyy&);
String year=simpleDateFormat.format(new Date());
this.age=Integer.parseInt(year)-this.
} catch (Exception e) {
e.printStackTrace();
* @return the province
public String getProvince() {
* @return the city
public String getCity() {
* @return the region
public String getRegion() {
* @return the year
public int getYear() {
* @return the month
public int getMonth() {
* @return the day
public int getDay() {
* @return the gender
public String getGender() {
* @return the birthday
public Date getBirthday() {
public String toString() {
return &省份:& + this.province + &,性别:& + this.gender + &,出生日期:&
public static void main(String[] args) {
String idcard = &&;
IdcardInfoExtractor ie = new IdcardInfoExtractor(idcard);
System.out.println(ie.toString());
public int getAge() {
public void setAge(int age) {
this.age =
import java.util.D
public class Test {
public static void main(String[] args) {
IdcardInfoExtractor idcardInfo=new IdcardInfoExtractor(&061825&);
System.out.println(&出生日期:&+idcardInfo.getYear()+&-&+idcardInfo.getMonth()+&-&+idcardInfo.getDay());
System.out.println(&性别:&+idcardInfo.getGender());
System.out.println(&年龄:&+idcardInfo.getAge());
System.out.println(&省份:&+idcardInfo.getProvince());
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:123794次
积分:1736
积分:1736
排名:千里之外
原创:36篇
转载:30篇
评论:29条
(1)(2)(1)(3)(1)(25)(14)(6)(4)(3)(1)(1)(3)(1)

我要回帖

更多关于 小米官网下单多久发货 的文章

 

随机推荐