Commit 8514774c authored by hanfeng's avatar hanfeng

修改实名认证

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