...
|
...
|
@@ -2,6 +2,7 @@ package com.yohoufo.user.service.impl; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alipay.api.response.AlipayUserCertifyOpenQueryResponse;
|
|
|
import com.yoho.core.security.AlipayOpenapiHelper;
|
|
|
import com.yoho.tools.common.beans.ApiResponse;
|
|
|
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
|
|
|
import com.yohoufo.common.constant.CertPhotoEnum;
|
...
|
...
|
@@ -51,6 +52,9 @@ public class CertificationServiceImpl implements ICertificationService { |
|
|
@Value("${ufo.certification.timesLimit:3}")
|
|
|
private int certTimesLimit;
|
|
|
|
|
|
@Autowired
|
|
|
AlipayOpenapiHelper alipayOpenapiHelper;
|
|
|
|
|
|
@Override
|
|
|
public AuthorizeResultRespVO beginCertificate(RealNameAuthorizeReqVO reqVO) {
|
|
|
logger.info("BeginCertificate: Begin select valid certification record. reqVO is {}", reqVO);
|
...
|
...
|
@@ -168,6 +172,124 @@ public class CertificationServiceImpl implements ICertificationService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ApiResponse queryUserCertifyEx(RealNameAuthorizeReqVO reqVO) {
|
|
|
try {
|
|
|
logger.info("queryUserCertify: enter. reqVO is {}", reqVO);
|
|
|
//(0) 删除实名认证信息缓存
|
|
|
try {
|
|
|
cacheService.delZhiMaCert(reqVO.getUid());
|
|
|
}catch(Exception e){
|
|
|
logger.warn("queryUserCertify: delZhiMaCert redis fail, uid is {}, e is {}");
|
|
|
}
|
|
|
//(1) 根据 bizNo 查询认证信息是否存在
|
|
|
ZhiMaCert zhiMaCert = zhiMaCertDao.selectByBizNo(reqVO.getZhiMaBizNo());
|
|
|
if (zhiMaCert == null || StringUtils.isEmpty(zhiMaCert.getBizNo())) {
|
|
|
logger.warn("queryUserCertify: certInfo is null. reqVO is {}", reqVO);
|
|
|
throw new UfoServiceException(400, "未找到身份认证信息!");
|
|
|
}
|
|
|
//(2) 身份认证结果获取(调用支付宝接口)并更新
|
|
|
AlipayUserCertifyOpenQueryResponse response = AlipayCertHelper.alipayCertifyResultEx(zhiMaCert.getBizNo(), alipayOpenapiHelper);
|
|
|
logger.info("queryUserCertify: queryUserCert by alipay success. reqVO is {}, certResult is {}", reqVO, response);
|
|
|
if(!response.isSuccess()){
|
|
|
logger.info("queryUserCertify: fail. reqVO is {}", reqVO);
|
|
|
throw new UfoServiceException(400, "查询身份认证结果失败");
|
|
|
}
|
|
|
JSONObject result = JSONObject.parseObject(response.getBody()).getJSONObject("alipay_user_certify_open_query_response");
|
|
|
if("Success".equals(result.get("msg")) && "T".equals(result.get("passed"))){
|
|
|
int updateCount = zhiMaCertDao.updateValidStatusByPrimaryKey(zhiMaCert.getId());
|
|
|
if(updateCount < 1){
|
|
|
logger.warn("queryUserCertify: update certResult fail. reqVO is {}", reqVO);
|
|
|
throw new UfoServiceException(400, "更新身份认证结果失败!");
|
|
|
}
|
|
|
logger.info("queryUserCertify: userCert pass. reqVO is {}, certResult is {}", reqVO, response);
|
|
|
return new ApiResponse<>(200, "身份认证通过", true);
|
|
|
}else{
|
|
|
String errorMsg = result.getString("sub_msg");//认证不通过可能是出现异常情况
|
|
|
logger.info("queryUserCertify: userCert notPass. reqVO is {}, certResult is {}", reqVO, response);
|
|
|
return new ApiResponse<>(400, StringUtils.isEmpty(errorMsg) ? "身份认证不通过" : errorMsg ,false);
|
|
|
}
|
|
|
|
|
|
}catch(Exception e){
|
|
|
logger.warn("queryUserCertify: error. reqVO is {}, e is {}", reqVO, e);
|
|
|
throw new UfoServiceException(400, "查询身份认证结果失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 开始实名认证(支付宝实名身份证认证)
|
|
|
* @param reqVO 实名认证用户信息(包含身份证照片,姓名,身份证号码)
|
|
|
* @return 认证结果
|
|
|
*/
|
|
|
public AuthorizeResultRespVO beginCertificateEx(RealNameAuthorizeReqVO reqVO) {
|
|
|
logger.info("beginCertificateEx: Begin select valid certification record. reqVO is {}", reqVO);
|
|
|
|
|
|
this.checkIsLimited(reqVO.getUid()); //(1)判断当前实名认证次数是否超限(每个用户一天最多实名认证3次)
|
|
|
|
|
|
|
|
|
int uid = reqVO.getUid(); //(2)直接查询当前UID实名认证的记录
|
|
|
ZhiMaCert zhiMaCert = zhiMaCertDao.selectLatestCertificateByUid(uid);
|
|
|
logger.info("beginCertificateEx: get user certification history by uid. uid is {}, zhiMaCert is {}", uid, zhiMaCert);
|
|
|
|
|
|
//(3)是否已经认证通过,认证通过的直接返回.(以防万一,一般都是没有认证通过的)
|
|
|
if(null != zhiMaCert && CertPhotoEnum.isValidStatus(zhiMaCert.getValidPhoto()) && 1 == zhiMaCert.getValidStatus()){
|
|
|
logger.info("beginCertificateEx: user has certification already. uid is {}", uid);
|
|
|
throw new UfoServiceException(400, "已实名认证!");
|
|
|
}
|
|
|
|
|
|
//(4)如果客户端传入的身份信息是隐位信息,那么将身份信息进行补全。
|
|
|
if(null != zhiMaCert && (reqVO.getCertName().contains("*") || reqVO.getCertNo().contains("*"))){
|
|
|
reqVO.setCertName(zhiMaCert.getCertName());
|
|
|
reqVO.setCertNo(zhiMaCert.getCertNo());
|
|
|
logger.info("beginCertificateEx:zhiMaCertWithPhotoCheckInit reset mask ,zhiMaCert {} ,new reqVO is {}", zhiMaCert ,reqVO);
|
|
|
}
|
|
|
|
|
|
//(5) 判断用户新传入的身份信息,是否与历史认证一致,如果不一致,需要重新进行OCR识别+支付宝刷脸认证。
|
|
|
if(null != zhiMaCert && (!reqVO.getCertName().equals(zhiMaCert.getCertName()) || !reqVO.getCertNo().equals(zhiMaCert.getCertNo()))){
|
|
|
logger.info("beginCertificateEx: request cert info not matched in db. reqVO is {}, zhiMaCert is {}", reqVO, zhiMaCert);
|
|
|
zhiMaCert = null;
|
|
|
}
|
|
|
|
|
|
//----------------------以下是需要实名认证(身份证OCR识别 + 支付宝刷脸认证)-------------------------------
|
|
|
AuthorizeResultRespVO respBO = new AuthorizeResultRespVO();
|
|
|
respBO.setCallZhiMa("0");
|
|
|
|
|
|
//(6)身份证OCR识别(已经识别过将不会继续识别)
|
|
|
if(null == zhiMaCert || !CertPhotoEnum.isValidStatus(zhiMaCert.getValidPhoto())){
|
|
|
ocrCertPhotoService.IDOCRIdentification(reqVO, zhiMaCert); //OCR身份证识别
|
|
|
logger.info("beginCertificateEx: ocr identification result. reqVO is {}", reqVO);
|
|
|
}
|
|
|
|
|
|
//(7)如果是首次认证,记录入库,否则更新认证记录
|
|
|
if(null == zhiMaCert){
|
|
|
zhiMaCert = new ZhiMaCert();
|
|
|
zhiMaCert.setUid(reqVO.getUid());
|
|
|
zhiMaCert.setValidStatus(9);//用户还未授权,暂时未生效 ,初始值为9
|
|
|
zhiMaCert.setCertName(reqVO.getCertName());
|
|
|
zhiMaCert.setCertNo(reqVO.getCertNo());
|
|
|
zhiMaCert.setImageUrl(reqVO.getFrontImageUrl()+","+reqVO.getBackImageUrl());
|
|
|
zhiMaCert.setValidPhoto(1); // 实名和身份证照片是一起验证的
|
|
|
zhiMaCert.setCreateTime(System.currentTimeMillis()/1000);
|
|
|
zhiMaCert.setUpdateTime(System.currentTimeMillis()/1000);
|
|
|
zhiMaCertDao.insertAndGetID(zhiMaCert);
|
|
|
}else if(null != zhiMaCert && !CertPhotoEnum.isValidStatus(zhiMaCert.getValidPhoto())){
|
|
|
zhiMaCertDao.updatePhotoResult(zhiMaCert.getId(), reqVO.getFrontImageUrl()+","+reqVO.getBackImageUrl(),
|
|
|
reqVO.getPhotoValidStatus(), System.currentTimeMillis()/1000);
|
|
|
}
|
|
|
logger.info("beginCertificateEx: save db success. reqVO is {}, zhiMaCert is {}", reqVO, zhiMaCert);
|
|
|
|
|
|
//(8)支付宝实名认证(如果已经认证过了,将不会继续认证)
|
|
|
if(null == zhiMaCert || 1 != zhiMaCert.getValidStatus()) {
|
|
|
alipayService.beginAlipayCertEx(reqVO, zhiMaCert, respBO); //开始支付宝刷脸认证
|
|
|
logger.info("beginCertificateEx: call alipay certify end. reqVO is {}, zhiMaCert is {}, respBO is {}", reqVO, zhiMaCert, respBO);
|
|
|
}
|
|
|
|
|
|
cacheService.delZhiMaCertNoException(reqVO.getUid()); //(9)删除实名认证信息缓存
|
|
|
|
|
|
return respBO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断当前用户使用实名认证的次数是否超限,默认3次
|
|
|
* @param uid
|
...
|
...
|
|