java校验身份证信息-调用第三方(聚合API)

版权声明:本文为博主搜索整合文章。 https://blog.csdn.net/weixin_37794901/article/details/79175118

HttpClient httpClient = HttpClientBuilder.create().build();
ObjectMapper mapper = new ObjectMapper();
HttpGet httpGet = null;
HttpResponse response = null;
HttpEntity entity = null;
String responseString = null;
httpGet = new HttpGet(ID_URL + "?key=" + ID_APP_KEY_WWW + "&idcard=" +IDNumber + "&realname=" + name);
try {
response = httpClient.execute(httpGet);
entity = response.getEntity();
responseString = EntityUtils.toString(entity, "UTF-8");
log.getLogger("wantmap_s").info("WMPrizeService.ValidIdResponse:{}", responseString);
JsonNode node = mapper.readTree(responseString);
if (0 != (node.get("error_code").asInt())) {
throw new IllegalStateException("身份证信息异常");
}
else {
if (1 == node.get("result").get("res").asInt()) {
// return true;
}
else {
throw new IllegalStateException("身份证信息异常");
}
}
}
catch (ClientProtocolException e) {
log.getLogger("cjn_s").info("end WMPrizeService.claimInfoIsValid:{},{}", name+IDNumber, e.getMessage());
}
catch (IOException e) {
log.getLogger("cjn_s").info("end WMPrizeService.claimInfoIsValid:{},{}", name+IDNumber, e.getMessage());
}


PS: public static final String ID_APP_KEY_WWW = "xxxxxxxxxxxxxxxxx"; // 身份认证
public static final String ID_URL = "xxxxxxxxxxxxx";// 身份认证url

需要在聚合API申请

猜你喜欢

转载自blog.csdn.net/weixin_37794901/article/details/79175118
今日推荐