Commit 8514774c authored by hanfeng's avatar hanfeng

修改实名认证

parent a9e5d34e
......@@ -57,33 +57,23 @@ public class CertificationController {
*/
@PostMapping("/app/certificate")
public ObjectRestResponse certificate(@RequestBody IdInformation idInformation, HttpServletRequest request) {
if (idInformation == null) {
ObjectRestResponse.createDefaultFail();
ObjectRestResponse.createFailedResult(ResultCode.INCOMPLETE_DATA,"无法识别,请重新上传");
}
String token = request.getHeader("Authorization");
log.info("------token======"+token);
if (StringUtils.isEmpty(token)) {
ObjectRestResponse.createFailedResult(ResultCode.RSTOKEN_NULL_CODE,"无法识别,请重新上传");
}
//获得用户信息
ObjectRestResponse<AppUserDTO> appUserDTOObjectRestResponse= userFeign.userDetailByToken(token);
log.info("----用户信息========="+appUserDTOObjectRestResponse.getData());
if (appUserDTOObjectRestResponse==null||appUserDTOObjectRestResponse.getData()==null||appUserDTOObjectRestResponse.getData().getId()==0) {
return ObjectRestResponse.createFailedResult(ResultCode.GET_APPUSER_FAILED_CODE,"无法识别,请重新上传");
return ObjectRestResponse.createFailedResult(ResultCode.GET_APPUSER_FAILED_CODE,"无法识别,请重新上传");
}
AppUserDTO appUserDTO = appUserDTOObjectRestResponse.getData();
idInformation.setUserLonginId(appUserDTO.getUserid());
//获取用户认证信息
ObjectRestResponse orr = null;
try {
......@@ -91,12 +81,9 @@ public class CertificationController {
} catch (Exception e) {
e.printStackTrace();
}
if (orr==null) {
return ObjectRestResponse.createFailedResult(ResultCode.GET_AUTH_INFO_FAILED_CODE,"无法识别,请重新上传");
}
Integer type = idInformation.getCertificateType();
log.info("----type========="+type);
try {
......@@ -116,7 +103,6 @@ public class CertificationController {
} catch (Exception e) {
e.printStackTrace();
}
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"无法识别,请重新上传");
}
......
......@@ -147,60 +147,41 @@ public class CertificationService {
//携带返回参数的map
HashedMap hashMap = new HashedMap();
// 认证状态:true是认证过
//判断是否bean是否为null
if (idInformation == null) {
return ObjectRestResponse.createFailedResult(ResultCode.INCOMPLETE_DATA, "无法识别,请重新上传");
}
//判断是否有填写身份证号
if (StringUtils.isBlank(idInformation.getIdNumber())) {
return ObjectRestResponse.createFailedResult(ResultCode.INCOMPLETE_DATA, "未填写证件号");
}
if (!Validation.isIdCard(idInformation.getIdNumber())) {
return ObjectRestResponse.createFailedResult(ResultCode.WRONG_FORMAT_OF_ID_CARD, "填写的证件格式错误");
}
//判断是有否填写名字
if (StringUtils.isBlank(idInformation.getName())) {
return ObjectRestResponse.createFailedResult(ResultCode.INCOMPLETE_DATA, "未填写姓名");
}
//判断是否有正面照片
if (StringUtils.isBlank(idInformation.getFrontUrl())) {
return ObjectRestResponse.createFailedResult(ResultCode.INCOMPLETE_DATA, "请上传正面照");
}
//判断是否有背面照片
if (StringUtils.isBlank(idInformation.getBackUrl())) {
return ObjectRestResponse.createFailedResult(ResultCode.INCOMPLETE_DATA, "请上传背面照");
}
//2.解析
//正面进行解析
String front = imageParse(idInformation.getFrontUrl(), frontParameter);
//解析证件背面
String back = imageParse(idInformation.getBackUrl(), backParameter);
log.info("----解析front=========" + front);
log.info("----解析back=========" + back);
if (StringUtils.isBlank(front) || StringUtils.isBlank(back)) {
return ObjectRestResponse.createDefaultFail();
return ObjectRestResponse.createFailedResult(ResultCode.INCOMPLETE_DATA,"无法识别,请重新上传");
}
Map frontMap = (Map) JSONObject.parse(front);
//反面进行解析
Map backMap = (Map) JSONObject.parse(back);
......@@ -209,33 +190,21 @@ public class CertificationService {
|| !(frontMap.get(imageRet).equals(imageResultCode))
|| MapUtil.isEmpty(backMap)
|| !(backMap.get(imageRet).equals(imageResultCode))
) {
return ObjectRestResponse.createDefaultFail();
return ObjectRestResponse.createFailedResult(ResultCode.INCOMPLETE_DATA,"无法识别,请重新上传");
}
Map frontData = (Map) frontMap.get(dataNam);
Map backData = (Map) backMap.get(dataNam);
if (MapUtil.isEmpty(backData) || MapUtil.isEmpty(frontData)) {
return ObjectRestResponse.createDefaultFail();
return ObjectRestResponse.createFailedResult(ResultCode.INCOMPLETE_DATA,"无法识别,请重新上传");
}
//解析通过,进行匹配
String name = (String) frontData.get(iName);
String number = (String) frontData.get(numberName);
if (idInformation.getName().equals(name)) {
ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE, "姓名不一致");
}
if (idInformation.getIdNumber().equals(number)) {
ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE, "证件号不一致");
}
......@@ -243,33 +212,23 @@ public class CertificationService {
//map携带身份证和姓名进行认证
Map<String, String> authMap = new HashMap<>();
authMap.put(idCardName, (String) frontData.get(numberName));
authMap.put(cName, (String) frontData.get(cName));
//3.调用接口进行认证
String result = certificate(authMap);
log.info("----认证结果result=========" + result);
//认证返回的参数是否为空
if (!StringUtils.isBlank(result)) {
Map<String, Object> map = (Map<String, Object>) JSONObject.parse(result);
log.info("----certifRet=========" + certifRet);
if (MapUtil.isNotEmpty(map) || certifResultCode.equals(map.get(certifRet))) {
//认证成功后存入保存到数据库
//获得身份证正面记录的身份证号和真实姓名
//设置姓名
idInformation.setName((String) frontData.get(iName));
//设置身份证号
idInformation.setIdNumber((String) frontData.get(numberName));
//获得到期时间
String endDate = (String) backData.get(expirationDateName);
log.info("----获得到期时间endDate=========" + endDate);
if (StringUtils.isBlank(endDate)) {
return ObjectRestResponse.succ();
......@@ -281,16 +240,14 @@ public class CertificationService {
c.setTime(date);
c.add(Calendar.YEAR, 100);
expirationDate = c.getTime();
} else {
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
formatter.setLenient(false);
try {
expirationDate = formatter.parse(endDate);
} catch (ParseException e) {
e.printStackTrace();
return ObjectRestResponse.createDefaultFail();
return ObjectRestResponse.createFailedResult(ResultCode.INCOMPLETE_DATA,"无法识别,请重新上传");
}
}
idInformation.setExpirationDate(expirationDate);
......@@ -300,7 +257,6 @@ public class CertificationService {
if (objRR.getRel()) {
return ObjectRestResponse.succ(objRR.getData());
}
}
}
......@@ -313,34 +269,22 @@ public class CertificationService {
//认证
public String certificate(Map<String, String> querys) {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "APPCODE " + cAppcode);
//
//
try {
log.info("----querys=========" + querys);
HttpResponse response = CertifHttpUtils.doGet(cHost, cPath, cMethod, headers, querys);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
/**
* 状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误
*/
//获取response的body
if (statusCode == 200) {
return EntityUtils.toString(response.getEntity());
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
......@@ -348,27 +292,16 @@ public class CertificationService {
//身份证照片解析
public String imageParse(String imageUrl, String type) {
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + iAppcode);
Map<String, String> querys = new HashMap<String, String>();
Map<String, String> bodys = new HashMap<String, String>();
bodys.put(picName, imageUrl);
//默认正面front,背面请传back
bodys.put(typeName, type);
try {
HttpResponse response = CertifHttpUtils.doPost(iHost, iPath, iMethod, headers, querys, bodys);
StatusLine statusLine = response.getStatusLine();
......@@ -383,9 +316,7 @@ public class CertificationService {
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
......@@ -422,7 +353,7 @@ public class CertificationService {
} catch (Exception e) {
e.printStackTrace();
TransactionAspectSupport.currentTransactionStatus();
return ObjectRestResponse.createDefaultFail();
return ObjectRestResponse.createFailedResult(ResultCode.INCOMPLETE_DATA,"无法识别,请重新上传");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment