根据车牌获取信息 pom 文件

主方法.代码不全.有需要的联系我. (461607143)


package com.bofide.getCarInfo;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;


import org.apache.http.NoHttpResponseException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bofide.Utils.CarRegular;
import com.bofide.Utils.CheckIdCardUtils;
import com.bofide.Utils.HttpClient;
import com.bofide.Utils.Utilityclass;
import com.bofide.dao.Activity;
import com.bofide.dao.GetCarInfoDao;


/**
 * 总方法(获取车辆信息)
 * 
 * @author Administrator
 *
 */
public class GetCarsInfo {
private static Logger logger = Logger.getLogger(GetCarsInfo.class);
static JSONObject message = new JSONObject();


public static void getCarInfo(String select) {
Properties load = null;
logger.info("==========读取配置文件开始==========");
try {
// 读取配置文件
load = Utilityclass.load("db.properties");
} catch (Exception e) {
// TODO Auto-generated catch block
message.put("message", "配置文件读取失败!!");
message.put("success", false);
logger.info("配置文件读取失败!!");
e.printStackTrace();
}
logger.info("读取配置文件" + load);
logger.info("==========读取配置文件结束==========");
// 读取数据返回
JSONArray param = GetCarInfoDao.getParam(select, load.getProperty("rows"));
logger.info("param==>" + param);
// 查询数据
for (int i = 0; i < param.size(); i++) {
JSONObject info = new JSONObject();
JSONObject sendParam = param.getJSONObject(i);
String underwayId = sendParam.getString("id");
info.put("id", underwayId);
// 查过的数据不去查
if (sendParam.containsKey("sign") && sendParam.getString("sign").equals("0")) {


logger.info("查询进度:" + underwayId);
boolean carNoRegular = CarRegular.carNoRegular(sendParam.getString("vehicleLicenceCode"));
logger.info("车牌号验证:  " + sendParam.getString("vehicleLicenceCode") + "==>" + carNoRegular);
if (carNoRegular) {


try {
// 睡觉
int randomTime = Utilityclass.randomTime();
logger.info("睡觉.." + (randomTime+Integer.parseInt(load.getProperty("sleepTime"))*60000));
Thread.sleep(randomTime);
} catch (InterruptedException e1) { // TODO Auto-generated
// catch block
e1.printStackTrace();
logger.info("随机时间异常!");
}
// 查询数据
try {
sendParam.put("carsPriceUrl", load.getProperty("carsPriceUrl"));
info = getInfo(sendParam);
info.put("id", underwayId);
} catch (Exception e) {
// TODO Auto-generated catch block
// 异常等十分钟再查询
info.put("id", underwayId);
info.put("success", false);
info.put("message", "异常");
logger.info("异常(超时),等十分钟查!");
e.printStackTrace();
break;
}
}
// 写数据
writeInfo(info);
}
}
}


/**
* 写数据

* @param jsonObject

*/
private final static void writeInfo(JSONObject jsonObject) {
// TODO Auto-generated method stub
Activity activity = new Activity();
logger.info("写数据源==>" + jsonObject);
if (jsonObject != null && !jsonObject.equals("")) {
String id = jsonObject.getString("id");
if (jsonObject.getBooleanValue("success")) {
// 写数据
if (jsonObject.containsKey("data")) {
JSONObject data = jsonObject.getJSONObject("data");
activity.setSign("1");
activity.setId(Utilityclass.stringToInt(id));
// ownerName
activity.setOwnerName(data.containsKey("ownerName") ? data.getString("ownerName") : "");
// ownerProp
activity.setOwnerProp(data.containsKey("ownerProp") ? data.getString("ownerProp") : "");


// modelType
activity.setModelType(data.containsKey("modelType") ? data.getString("modelType") : "");
// moldCharacterCode
activity.setMoldCharacterCode(
data.containsKey("moldCharacterCode") ? data.getString("moldCharacterCode") : "");
// createdDate
activity.setCreatedDate(data.containsKey("createdDate") ? data.getString("createdDate") : "");
// newCarPrice
activity.setNewCarPrice(data.containsKey("newCarPrice") ? data.getString("newCarPrice") : "");
// insuranceEndTime
activity.setInsuranceEndTime(
data.containsKey("insuranceEndTime") ? data.getString("insuranceEndTime") : "");
// businessEndTime
activity.setBusinessEndTime(
data.containsKey("businessEndTime") ? data.getString("businessEndTime") : "");
// insuranceType
activity.setInsuranceType(data.containsKey("insuranceType") ? data.getString("insuranceType") : "");
// address
// 查询归属地
String certNo = data.getString("certNo");
String provinceByIdCard = "";
if (CheckIdCardUtils.validateCard(certNo)) {
provinceByIdCard = CheckIdCardUtils.getProvinceByIdCard(certNo);
System.out.println(provinceByIdCard);
}
activity.setAddress(
provinceByIdCard != null && !provinceByIdCard.equals("") ? provinceByIdCard : "");


// certNo
activity.setCertNo(data.containsKey("certNo") ? data.getString("certNo") : "");
// remarks 备注
activity.setRemarks("查询成功!");
// 写入数据
int update = GetCarInfoDao.update(activity);
if (update == 1) {
logger.info("写入数据成功!");
} else {
logger.info("写入数据失败!");
}
}
} else if (jsonObject.containsKey("message") && jsonObject.getString("message").equals("异常")) {
activity.setId(Utilityclass.stringToInt(id));
// remarks 备注
activity.setRemarks("获取数据异常!");
activity.setSign("0");
// 写入数据
int update = GetCarInfoDao.update(activity);
if (update == 1) {
logger.info("写入数据成功!");
} else {
logger.info("写入数据失败!");
}
} else {
// 写信息
activity.setId(Utilityclass.stringToInt(id));
// remarks 备注
activity.setRemarks("查询无数据!");
activity.setSign("1");
// 写入数据
int update = GetCarInfoDao.update(activity);
if (update == 1) {
logger.info("写入数据成功!");
} else {
logger.info("写入数据失败!");
}
}


}
}


/**
* 执行查询

* @param printBody
* @param load
* @return
* @throws Exception
*/
private final static JSONObject getInfo(JSONObject carInfo) throws Exception {
// TODO Auto-generated method stub


Map<String, Object> hashMap = new HashMap<String, Object>();
if (carInfo.isEmpty() || carInfo == null || carInfo.equals("{}")) {
carInfo.put("message", "printBody无数据!");
carInfo.put("success", false);
logger.info("没有传入数据数据...");
}


String vehicleLicenceCode = carInfo.containsKey("vehicleLicenceCode")
&& carInfo.getString("vehicleLicenceCode") != null
&& !carInfo.getString("vehicleLicenceCode").equals("") ? carInfo.getString("vehicleLicenceCode") : "";
/*
* String plateType = carInfo.containsKey("plateType") &&
* carInfo.getString("plateType") != null &&
* !carInfo.getString("plateType").equals("") ?
* carInfo.getString("plateType") : "";
*/
String engineNo = carInfo.containsKey("engineNo") && carInfo.getString("engineNo") != null
&& !carInfo.getString("engineNo").equals("") ? carInfo.getString("engineNo") : "";


/*
* String vehicleFrameNo = carInfo.containsKey("vehicleFrameNo") &&
* carInfo.getString("vehicleFrameNo") != null &&
* !carInfo.getString("vehicleFrameNo").equals("") ?
* carInfo.getString("vehicleFrameNo") : "";
*/
String vehicleFrameNo = carInfo.containsKey("vehicleFrameNo") && carInfo.getString("vehicleFrameNo") != null
&& !carInfo.getString("vehicleFrameNo").equals("") ? carInfo.getString("vehicleFrameNo") : "";


JSONObject jsonObject = new JSONObject();
jsonObject.put("vehicleLicenceCode", vehicleLicenceCode);
jsonObject.put("plateType", "02");
jsonObject.put("engineNo", engineNo);
jsonObject.put("vehicleFrameNo", vehicleFrameNo);
jsonObject.put("vin", "");


hashMap.put("token", "111");
hashMap.put("shopId", "1");
hashMap.put("args", jsonObject.toJSONString());
logger.info("执行查询的拼接数据==>" + hashMap);
// 121.41.82.99:9090/v1/getCarInfo?
// http://120.26.2.122:9090/v1/getCarInfo?


HttpUriRequest httpUriRequest = HttpClient.getHttpUriRequest("get", carInfo.getString("carsPriceUrl"), null,
hashMap, null, null);
String carsPriceStr = "";
JSONObject parseObject = new JSONObject();
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse carsPriceResponse = httpClient.execute(httpUriRequest);
carsPriceStr = EntityUtils.toString(carsPriceResponse.getEntity());
carsPriceResponse.close();
parseObject = JSONObject.parseObject(carsPriceStr);
logger.info("查询返回结果==>" + parseObject);


} catch (NoHttpResponseException e) {
parseObject.put("message", "查询错误!");
parseObject.put("success", false);
logger.info("车辆信息获取失败...");
}
return parseObject;
}


/**
* 半夜多睡会儿
*/
public static void execute(Properties load) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
try {
// 八点半开始执行. 十点结束
int nowTime = Integer.parseInt(sdf.format(new Date()).substring(11));
int startTime = Integer.parseInt(load.getProperty("startTime"));
int endTime = Integer.parseInt(load.getProperty("endTime"));
//
if (nowTime < startTime || nowTime >= endTime) {
logger.info("==========半夜了,睡觉==========");
if (nowTime < startTime)
Thread.sleep(1000 * 60 * 60 * (startTime - nowTime - 1));
if (nowTime >= endTime)
Thread.sleep(1000 * 60 * 60 * (24 - nowTime + startTime - 1));
}
} catch (Exception e) {
e.printStackTrace();
}
}


public static void main(String[] args) throws Exception {


String insert = GetCarInfoDao.select("0");
while (Utilityclass.stringToInt(insert) < 52373) {
Properties load = Utilityclass.load("db.properties");
// 休息时间
execute(load);
// 开始工作
insert = GetCarInfoDao.select("0");
getCarInfo(insert);
}
logger.info("查询结束!");
}
}


身份证的工具类

package com.bofide.Utils;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


import org.apache.http.Header;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;


import com.mysql.jdbc.StringUtils;


/**
 * 身份证工具类
 * 
 * @author June
 * @version 1.0, 2010-06-17
 */
public class CheckIdCardUtils extends StringUtils {


/** 中国公民身份证号码最小长度。 */
public static final int CHINA_ID_MIN_LENGTH = 15;


/** 中国公民身份证号码最大长度。 */
public static final int CHINA_ID_MAX_LENGTH = 18;


/** 省、直辖市代码表 */
public static final 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" };


/** 每位加权因子 */
public static final int power[] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };


/** 第18位校检码 */
public static final String verifyCode[] = { "1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2" };
/** 最低年限 */
public static final int MIN = 1930;
public static Map<String, String> cityCodes = new HashMap<String, String>();
/** 台湾身份首字母对应数字 */
public static Map<String, Integer> twFirstCode = new HashMap<String, Integer>();
/** 香港身份首字母对应数字 */
public static Map<String, Integer> hkFirstCode = new HashMap<String, Integer>();


static {
cityCodes.put("11", "北京");
cityCodes.put("12", "天津");
cityCodes.put("13", "河北");
cityCodes.put("14", "山西");
cityCodes.put("15", "内蒙古");
cityCodes.put("21", "辽宁");
cityCodes.put("22", "吉林");
cityCodes.put("23", "黑龙江");
cityCodes.put("31", "上海");
cityCodes.put("32", "江苏");
cityCodes.put("33", "浙江");
cityCodes.put("34", "安徽");
cityCodes.put("35", "福建");
cityCodes.put("36", "江西");
cityCodes.put("37", "山东");
cityCodes.put("41", "河南");
cityCodes.put("42", "湖北");
cityCodes.put("43", "湖南");
cityCodes.put("44", "广东");
cityCodes.put("45", "广西");
cityCodes.put("46", "海南");
cityCodes.put("50", "重庆");
cityCodes.put("51", "四川");
cityCodes.put("52", "贵州");
cityCodes.put("53", "云南");
cityCodes.put("54", "西藏");
cityCodes.put("61", "陕西");
cityCodes.put("62", "甘肃");
cityCodes.put("63", "青海");
cityCodes.put("64", "宁夏");
cityCodes.put("65", "新疆");
cityCodes.put("71", "台湾");
cityCodes.put("81", "香港");
cityCodes.put("82", "澳门");
cityCodes.put("91", "国外");
twFirstCode.put("A", 10);
twFirstCode.put("B", 11);
twFirstCode.put("C", 12);
twFirstCode.put("D", 13);
twFirstCode.put("E", 14);
twFirstCode.put("F", 15);
twFirstCode.put("G", 16);
twFirstCode.put("H", 17);
twFirstCode.put("J", 18);
twFirstCode.put("K", 19);
twFirstCode.put("L", 20);
twFirstCode.put("M", 21);
twFirstCode.put("N", 22);
twFirstCode.put("P", 23);
twFirstCode.put("Q", 24);
twFirstCode.put("R", 25);
twFirstCode.put("S", 26);
twFirstCode.put("T", 27);
twFirstCode.put("U", 28);
twFirstCode.put("V", 29);
twFirstCode.put("X", 30);
twFirstCode.put("Y", 31);
twFirstCode.put("W", 32);
twFirstCode.put("Z", 33);
twFirstCode.put("I", 34);
twFirstCode.put("O", 35);
hkFirstCode.put("A", 1);
hkFirstCode.put("B", 2);
hkFirstCode.put("C", 3);
hkFirstCode.put("R", 18);
hkFirstCode.put("U", 21);
hkFirstCode.put("Z", 26);
hkFirstCode.put("X", 24);
hkFirstCode.put("W", 23);
hkFirstCode.put("O", 15);
hkFirstCode.put("N", 14);
}


/**
* 将15位身份证号码转换为18位

* @param idCard
*            15位身份编码
* @return 18位身份编码
*/
public static String conver15CardTo18(String idCard) {
String idCard18 = "";
if (idCard.length() != CHINA_ID_MIN_LENGTH) {
return null;
}
if (isNum(idCard)) {
// 获取出生年月日
String birthday = idCard.substring(6, 12);
Date birthDate = null;
try {
birthDate = new SimpleDateFormat("yyMMdd").parse(birthday);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar cal = Calendar.getInstance();
if (birthDate != null)
cal.setTime(birthDate);
// 获取出生年(完全表现形式,如:2010)
String sYear = String.valueOf(cal.get(Calendar.YEAR));
idCard18 = idCard.substring(0, 6) + sYear + idCard.substring(8);
// 转换字符数组
char[] cArr = idCard18.toCharArray();
if (cArr != null) {
int[] iCard = converCharToInt(cArr);
int iSum17 = getPowerSum(iCard);
// 获取校验位
String sVal = getCheckCode18(iSum17);
if (sVal.length() > 0) {
idCard18 += sVal;
} else {
return null;
}
}
} else {
return null;
}
return idCard18;
}


/**
* 验证身份证是否合法
*/
public static boolean validateCard(String idCard) {
String card = idCard.trim();
if (validateIdCard18(card)) {
return true;
}
if (validateIdCard15(card)) {
return true;
}
String[] cardval = validateIdCard10(card);
if (cardval != null) {
if (cardval[2].equals("true")) {
return true;
}
}
return false;
}


/**
* 验证18位身份编码是否合法

* @param idCard
*            身份编码
* @return 是否合法
*/
public static boolean validateIdCard18(String idCard) {
boolean bTrue = false;
if (idCard.length() == CHINA_ID_MAX_LENGTH) {
// 前17位
String code17 = idCard.substring(0, 17);
// 第18位
String code18 = idCard.substring(17, CHINA_ID_MAX_LENGTH);
if (isNum(code17)) {
char[] cArr = code17.toCharArray();
if (cArr != null) {
int[] iCard = converCharToInt(cArr);
int iSum17 = getPowerSum(iCard);
// 获取校验位
String val = getCheckCode18(iSum17);
if (val.length() > 0) {
if (val.equalsIgnoreCase(code18)) {
bTrue = true;
}
}
}
}
}
return bTrue;
}


/**
* 验证15位身份编码是否合法

* @param idCard
*            身份编码
* @return 是否合法
*/
public static boolean validateIdCard15(String idCard) {
if (idCard.length() != CHINA_ID_MIN_LENGTH) {
return false;
}
if (isNum(idCard)) {
String proCode = idCard.substring(0, 2);
if (cityCodes.get(proCode) == null) {
return false;
}
String birthCode = idCard.substring(6, 12);
Date birthDate = null;
try {
birthDate = new SimpleDateFormat("yy").parse(birthCode.substring(0, 2));
} catch (ParseException e) {
e.printStackTrace();
}
Calendar cal = Calendar.getInstance();
if (birthDate != null)
cal.setTime(birthDate);
if (!valiDate(cal.get(Calendar.YEAR), Integer.valueOf(birthCode.substring(2, 4)),
Integer.valueOf(birthCode.substring(4, 6)))) {
return false;
}
} else {
return false;
}
return true;
}


/**
* 验证10位身份编码是否合法

* @param idCard
*            身份编码
* @return 身份证信息数组
*         <p>
*         [0] - 台湾、澳门、香港 [1] - 性别(男M,女F,未知N) [2] - 是否合法(合法true,不合法false)
*         若不是身份证件号码则返回null
*         </p>
*/
public static String[] validateIdCard10(String idCard) {
String[] info = new String[3];
String card = idCard.replaceAll("[\\(|\\)]", "");
if (card.length() != 8 && card.length() != 9 && idCard.length() != 10) {
return null;
}
if (idCard.matches("^[a-zA-Z][0-9]{9}{1}")) { // 台湾
info[0] = "台湾";
System.out.println("11111");
String char2 = idCard.substring(1, 2);
if (char2.equals("1")) {
info[1] = "M";
System.out.println("MMMMMMM");
} else if (char2.equals("2")) {
info[1] = "F";
System.out.println("FFFFFFF");
} else {
info[1] = "N";
info[2] = "false";
System.out.println("NNNN");
return info;
}
info[2] = validateTWCard(idCard) ? "true" : "false";
} else if (idCard.matches("^[1|5|7][0-9]{6}\\(?[0-9A-Z]\\)?{1}")) { // 澳门
info[0] = "澳门";
info[1] = "N";
// TODO
} else if (idCard.matches("^[A-Z]{1,2}[0-9]{6}\\(?[0-9A]\\)?{1}")) { // 香港
info[0] = "香港";
info[1] = "N";
info[2] = validateHKCard(idCard) ? "true" : "false";
} else {
return null;
}
return info;
}


/**
* 验证台湾身份证号码

* @param idCard
*            身份证号码
* @return 验证码是否符合
*/
public static boolean validateTWCard(String idCard) {
String start = idCard.substring(0, 1);
String mid = idCard.substring(1, 9);
String end = idCard.substring(9, 10);
Integer iStart = twFirstCode.get(start);
Integer sum = iStart / 10 + (iStart % 10) * 9;
char[] chars = mid.toCharArray();
Integer iflag = 8;
for (char c : chars) {
sum = sum + Integer.valueOf(c + "") * iflag;
iflag--;
}
return (sum % 10 == 0 ? 0 : (10 - sum % 10)) == Integer.valueOf(end) ? true : false;
}


/**
* 验证香港身份证号码(存在Bug,部份特殊身份证无法检查)
* <p>
* 身份证前2位为英文字符,如果只出现一个英文字符则表示第一位是空格,对应数字58 前2位英文字符A-Z分别对应数字10-35
* 最后一位校验码为0-9的数字加上字符"A","A"代表10
* </p>
* <p>
* 将身份证号码全部转换为数字,分别对应乘9-1相加的总和,整除11则证件号码有效
* </p>

* @param idCard
*            身份证号码
* @return 验证码是否符合
*/
public static boolean validateHKCard(String idCard) {
String card = idCard.replaceAll("[\\(|\\)]", "");
Integer sum = 0;
if (card.length() == 9) {
sum = (Integer.valueOf(card.substring(0, 1).toUpperCase().toCharArray()[0]) - 55) * 9
+ (Integer.valueOf(card.substring(1, 2).toUpperCase().toCharArray()[0]) - 55) * 8;
card = card.substring(1, 9);
} else {
sum = 522 + (Integer.valueOf(card.substring(0, 1).toUpperCase().toCharArray()[0]) - 55) * 8;
}
String mid = card.substring(1, 7);
String end = card.substring(7, 8);
char[] chars = mid.toCharArray();
Integer iflag = 7;
for (char c : chars) {
sum = sum + Integer.valueOf(c + "") * iflag;
iflag--;
}
if (end.toUpperCase().equals("A")) {
sum = sum + 10;
} else {
sum = sum + Integer.valueOf(end);
}
return (sum % 11 == 0) ? true : false;
}


/**
* 将字符数组转换成数字数组

* @param ca
*            字符数组
* @return 数字数组
*/
public static int[] converCharToInt(char[] ca) {
int len = ca.length;
int[] iArr = new int[len];
try {
for (int i = 0; i < len; i++) {
iArr[i] = Integer.parseInt(String.valueOf(ca[i]));
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
return iArr;
}


/**
* 将身份证的每位和对应位的加权因子相乘之后,再得到和值

* @param iArr
* @return 身份证编码。
*/
public static int getPowerSum(int[] iArr) {
int iSum = 0;
if (power.length == iArr.length) {
for (int i = 0; i < iArr.length; i++) {
for (int j = 0; j < power.length; j++) {
if (i == j) {
iSum = iSum + iArr[i] * power[j];
}
}
}
}
return iSum;
}


/**
* 将power和值与11取模获得余数进行校验码判断

* @param iSum
* @return 校验位
*/
public static String getCheckCode18(int iSum) {
String sCode = "";
switch (iSum % 11) {
case 10:
sCode = "2";
break;
case 9:
sCode = "3";
break;
case 8:
sCode = "4";
break;
case 7:
sCode = "5";
break;
case 6:
sCode = "6";
break;
case 5:
sCode = "7";
break;
case 4:
sCode = "8";
break;
case 3:
sCode = "9";
break;
case 2:
sCode = "x";
break;
case 1:
sCode = "0";
break;
case 0:
sCode = "1";
break;
}
return sCode;
}


/**
* 根据身份编号获取年龄

* @param idCard
*            身份编号
* @return 年龄
*/
public static int getAgeByIdCard(String idCard) {
int iAge = 0;
if (idCard.length() == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
String year = idCard.substring(6, 10);
Calendar cal = Calendar.getInstance();
int iCurrYear = cal.get(Calendar.YEAR);
iAge = iCurrYear - Integer.valueOf(year);
return iAge;
}


/**
* 根据身份编号获取生日

* @param idCard
*            身份编号
* @return 生日(yyyyMMdd)
*/
public static String getBirthByIdCard(String idCard) {
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
return idCard.substring(6, 14);
}


/**
* 根据身份编号获取生日年

* @param idCard
*            身份编号
* @return 生日(yyyy)
*/
public static Short getYearByIdCard(String idCard) {
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
return Short.valueOf(idCard.substring(6, 10));
}


/**
* 根据身份编号获取生日月

* @param idCard
*            身份编号
* @return 生日(MM)
*/
public static Short getMonthByIdCard(String idCard) {
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
return Short.valueOf(idCard.substring(10, 12));
}


/**
* 根据身份编号获取生日天

* @param idCard
*            身份编号
* @return 生日(dd)
*/
public static Short getDateByIdCard(String idCard) {
Integer len = idCard.length();
if (len < CHINA_ID_MIN_LENGTH) {
return null;
} else if (len == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
return Short.valueOf(idCard.substring(12, 14));
}


/**
* 根据身份编号获取性别

* @param idCard
*            身份编号
* @return 性别(M-男,F-女,N-未知)
*/
public static String getGenderByIdCard(String idCard) {
String sGender = "N";
if (idCard.length() == CHINA_ID_MIN_LENGTH) {
idCard = conver15CardTo18(idCard);
}
String sCardNum = idCard.substring(16, 17);
if (Integer.parseInt(sCardNum) % 2 != 0) {
sGender = "M";
} else {
sGender = "F";
}
return sGender;
}


/**
* 根据身份编号获取户籍省份

* @param idCard
*            身份编码
* @return
*/
public static String getProvinceByIdCard(String idCard) {
String method = "post";
// String uri = "http://sfz.ckd.cc/";
String uri = "https://idcard.911cha.com/";
Map<String, Object> map = new HashMap<String, Object>();
map.put("q", idCard);
String carsPriceStr = "";
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpUriRequest getRequest = HttpClient.getHttpUriRequest("get", uri, null, null, null, "utf-8");
CloseableHttpResponse execute = httpClient.execute(getRequest);
EntityUtils.toString(execute.getEntity());


Header[] headers = new Header[1];
headers[0] = new BasicHeader("Content-Type", "application/x-www-form-urlencoded");


// System.out.println(headers);
// System.out.println(getStr);
HttpUriRequest httpUriRequest = HttpClient.getHttpUriRequest(method, uri, headers, map, null, "utf-8");


CloseableHttpResponse carsPriceResponse = httpClient.execute(httpUriRequest);
carsPriceStr = EntityUtils.toString(carsPriceResponse.getEntity());
carsPriceResponse.close();
} catch (Exception e) {
// TODO: handle exception
}
// parseObject = JSONObject.parseObject(carsPriceStr);
// System.out.println("查询返回结果==>" + carsPriceStr);
String regularAddress = regularAddress(carsPriceStr);
return regularAddress;


}


/**
* 数字验证

* @param val
* @return 提取的数字。
*/
public static boolean isNum(String val) {
return val == null || "".equals(val) ? false : val.matches("^[0-9]*{1}");
}


/**
* 验证小于当前日期 是否有效

* @param iYear
*            待验证日期(年)
* @param iMonth
*            待验证日期(月 1-12)
* @param iDate
*            待验证日期(日)
* @return 是否有效
*/
public static boolean valiDate(int iYear, int iMonth, int iDate) {
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int datePerMonth;
if (iYear < MIN || iYear >= year) {
return false;
}
if (iMonth < 1 || iMonth > 12) {
return false;
}
switch (iMonth) {
case 4:
case 6:
case 9:
case 11:
datePerMonth = 30;
break;
case 2:
boolean dm = ((iYear % 4 == 0 && iYear % 100 != 0) || (iYear % 400 == 0)) && (iYear > MIN && iYear < year);
datePerMonth = dm ? 29 : 28;
break;
default:
datePerMonth = 31;
}
return (iDate >= 1) && (iDate <= datePerMonth);
}


/**
* 根据身份证号,自动获取对应的星座

* @param idCard
*            身份证号码
* @return 星座
*/
public static String getConstellationById(String idCard) {
if (!validateCard(idCard))
return "";
int month = CheckIdCardUtils.getMonthByIdCard(idCard);
int day = CheckIdCardUtils.getDateByIdCard(idCard);
String strValue = "";


if ((month == 1 && day >= 20) || (month == 2 && day <= 18)) {
strValue = "水瓶座";
} else if ((month == 2 && day >= 19) || (month == 3 && day <= 20)) {
strValue = "双鱼座";
} else if ((month == 3 && day > 20) || (month == 4 && day <= 19)) {
strValue = "白羊座";
} else if ((month == 4 && day >= 20) || (month == 5 && day <= 20)) {
strValue = "金牛座";
} else if ((month == 5 && day >= 21) || (month == 6 && day <= 21)) {
strValue = "双子座";
} else if ((month == 6 && day > 21) || (month == 7 && day <= 22)) {
strValue = "巨蟹座";
} else if ((month == 7 && day > 22) || (month == 8 && day <= 22)) {
strValue = "狮子座";
} else if ((month == 8 && day >= 23) || (month == 9 && day <= 22)) {
strValue = "处女座";
} else if ((month == 9 && day >= 23) || (month == 10 && day <= 23)) {
strValue = "天秤座";
} else if ((month == 10 && day > 23) || (month == 11 && day <= 22)) {
strValue = "天蝎座";
} else if ((month == 11 && day > 22) || (month == 12 && day <= 21)) {
strValue = "射手座";
} else if ((month == 12 && day > 21) || (month == 1 && day <= 19)) {
strValue = "魔羯座";
}


return strValue;
}


/**
* 根据身份证号,自动获取对应的生肖

* @param idCard
*            身份证号码
* @return 生肖
*/
public static String getZodiacById(String idCard) { // 根据身份证号,自动返回对应的生肖
if (!validateCard(idCard))
return "";


String sSX[] = { "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗" };
int year = CheckIdCardUtils.getYearByIdCard(idCard);
int end = 3;
int x = (year - end) % 12;


String retValue = "";
retValue = sSX[x];


return retValue;
}


/**
* 根据身份证号,自动获取对应的天干地支

* @param idCard
*            身份证号码
* @return 天干地支
*/
public static String getChineseEraById(String idCard) { // 根据身份证号,自动返回对应的生肖
if (!validateCard(idCard))
return "";


String sTG[] = { "癸", "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "任" };
String sDZ[] = { "亥", "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌" };


int year = CheckIdCardUtils.getYearByIdCard(idCard);
int i = (year - 3) % 10;
int j = (year - 3) % 12;


String retValue = "";
retValue = sTG[i] + sDZ[j];


return retValue;
}


/**
* 正则.身份证查出来的地址

* @param args
*/
private static String regularAddress(String str) {
String address = "";
if(str.indexOf("身份证号正确")>-1){


// 发证地:周口地区西华县生 日
int start = str.indexOf("发证地:");
int end = str.indexOf("生 日");


String substring = str.substring(start, end).replace("发证地:", "");
// System.out.println(address);
// String reg = "<span[^>]*>[^<]*</span>[^<]*<br />";
String reg = "[\u4e00-\u9fa5]";
Pattern pattern = Pattern.compile(reg);
Matcher match = pattern.matcher(substring);
while (match.find()) {// 取的每个dd标签
String dd = match.group();
address += dd;
}
}else{
address = "查询信息错误!";
}
return address;
}


public static void main(String[] args) {
// 验证身份证是否合法 发送请求,获取归属地 
String idCard = "632124199301293326";
if (validateCard(idCard)) {
System.out.println(getProvinceByIdCard(idCard));
} else {
System.out.println("身份证号码错误");
}
}
}


httpclient工具类

package com.bofide.Utils;


import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


import org.apache.http.Header;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.log4j.Logger;


public class HttpClient {
protected static CloseableHttpClient httpClient = null;
static HttpClientContext httpContext = null;
private static Logger logger = Logger.getLogger(HttpClient.class);
//
static RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30000)
.setConnectionRequestTimeout(30000).setSocketTimeout(30000).build();


/**

* @param method
* @param uri
* @return
* @throws UnsupportedEncodingException
* @throws URISyntaxException
*/
@SuppressWarnings("rawtypes")
public static HttpUriRequest getHttpUriRequest(String method, String uri, Header[] headers,
Map<String, Object> parms, String body, String charset)
throws UnsupportedEncodingException, URISyntaxException {
HttpUriRequest httpUriRequest = null;


if ("get".equalsIgnoreCase(method)) {
// 获取一个get请求!
logger.info("获取一个get请求!");
URI url = null;
URIBuilder uriBuilder = new URIBuilder(uri);
if (null != parms) {
for (Map.Entry<String, Object> entry : parms.entrySet()) {
if (entry.getValue() instanceof List) {
List values = (List) entry.getValue();
for (Object obj : values) {
uriBuilder.addParameter(entry.getKey(), obj == null ? "" : obj.toString());
}


} else {
uriBuilder.addParameter(entry.getKey(),
entry.getValue() == null ? "" : entry.getValue().toString());
}
}
}
url = uriBuilder.build();
HttpGet httpGet = new HttpGet(url);
httpGet.setConfig(requestConfig);
httpUriRequest = httpGet;


} else if ("post".equalsIgnoreCase(method)) {
// 获取一个post请求!
if (charset == null || charset.length() == 0) {
charset = "utf-8";
}


logger.info("获取一个post请求!");
HttpPost httpPost = new HttpPost(uri);
if (parms != null) {
ArrayList<NameValuePair> arrayList = new ArrayList<NameValuePair>();
Iterator<String> it = parms.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
if (parms.get(key) instanceof List) {
List values = (List) parms.get(key);
for (Object obj : values) {
arrayList.add(new BasicNameValuePair(key, obj == null ? "" : obj.toString()));
}
} else {
arrayList.add(
new BasicNameValuePair(key, parms.get(key) == null ? "" : parms.get(key).toString()));
}


}
UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(arrayList, charset);
httpPost.setEntity(uefEntity);


}
if (body != null && body.length() > 0) {
StringEntity entity = new StringEntity(body, charset);
httpPost.setEntity(entity);
}
httpPost.setConfig(requestConfig);
httpUriRequest = httpPost;
} else {
//
logger.info("必须请求GET/POST");
}
//
if (headers != null && headers.length > 0) {
httpUriRequest.setHeaders(headers);
}
return httpUriRequest;
}


/**
* @param request
* @throws Exception
*/
public static CloseableHttpResponse httpRequestExecute(HttpUriRequest request) throws Exception {
httpClient = HttpClients.createDefault();
return httpClient.execute(request, httpContext);


}
}


根据车牌获取信息 pom 文件


获取车辆信息,根据车牌号,车架号,发动机号. 


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bofide</groupId>
<artifactId>getBOFCarInfo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<mysql.version>5.1.24</mysql.version>
<spring.version>2.5.6</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>


<!-- https://mvnrepository.com/artifact/com.github.axet/kaptcha -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.2</version>
</dependency>


<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>


<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.11</version>
</dependency>


</dependencies>
<build>
<!-- com.bofide.getCarInfo.GetCarsInfo -->
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.bofide.getCarInfo.GetCarsInfo</mainClass>
</transformer>
</transformers>
</configuration>
</plugin>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<jar>${project.build.directory}/${artifactId}-${version}-shaded.jar</jar>
<outfile>${project.build.directory}/bofuGff.exe</outfile>
<downloadUrl>http://java.com/download</downloadUrl>
<classPath>
<mainClass>com.bofide.getCarInfo.GetCarsInfo</mainClass>
<preCp>anything</preCp>
</classPath>
<jre>
<minVersion>1.7.0</minVersion>
<jdkPreference>preferJre</jdkPreference>
</jre>
<versionInfo>
<fileVersion>1.0.0.0</fileVersion>
<txtFileVersion>${project.version}</txtFileVersion>
<fileDescription>${project.name}</fileDescription>
<copyright>2017 bofuGff.com</copyright>
<productVersion>1.0.0.0</productVersion>
<txtProductVersion>1.0.0.0</txtProductVersion>
<productName>${project.name}</productName>
<companyName>bofuGff.com</companyName>
<internalName>bofuGff</internalName>
<originalFilename>bofuGff.exe</originalFilename>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>查询出车辆信息 包括车辆的基本信息.车主信息.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白菜--jack

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值