Authored by 匡佳华

支付宝身份认证记录查询

... ... @@ -94,6 +94,28 @@ public class CertificationController {
return apiResponse;
}
/**
* 身份认证记录查询
* @param reqVO
* @return true: 通过, false: 不通过
* @throws GatewayException
*/
@RequestMapping(params = "method=ufo.user.alipayCertifyResultQuery")
public ApiResponse alipayCertifyResultQuery(RealNameAuthorizeReqVO reqVO) throws GatewayException {
logger.info("CertificationController.alipayCertifyResultQuery: Enter. RealNameAuthorizeReqVO is {}", reqVO);
//(1) 校验请求的参数
if (reqVO == null || reqVO.getUid() <= 0){
throw new GatewayException(400, "参数错误,uid不能为空!");
}
if(StringUtils.isBlank(reqVO.getZhiMaBizNo())){
throw new GatewayException(400, "参数错误,zhiMaBizNo不能为空!");
}
//(2) 调用支付宝接口查询认证结果
ApiResponse result = certificationService.queryUserCertify(reqVO);
logger.info("CertificationController.alipayCertifyResultQuery: End. result is {}", result);
return result;
}
... ...
... ... @@ -7,9 +7,11 @@ import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayUserCertifyOpenCertifyRequest;
import com.alipay.api.request.AlipayUserCertifyOpenInitializeRequest;
import com.alipay.api.request.AlipayUserCertifyOpenQueryRequest;
import com.alipay.api.request.ZhimaCustomerCertificationQueryRequest;
import com.alipay.api.response.AlipayUserCertifyOpenCertifyResponse;
import com.alipay.api.response.AlipayUserCertifyOpenInitializeResponse;
import com.alipay.api.response.AlipayUserCertifyOpenQueryResponse;
import com.alipay.api.response.ZhimaCustomerCertificationQueryResponse;
import java.util.UUID;
... ... @@ -112,29 +114,17 @@ public class AlipayCertificationHelper {
return null;
}
public static String alipayCertifyResult(String certify_id) throws AlipayApiException {
public static AlipayUserCertifyOpenQueryResponse alipayCertifyResult(String certify_id) throws AlipayApiException {
//获取alipay client
AlipayClient alipayClient = new DefaultAlipayClient(ALI_URL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE);
AlipayUserCertifyOpenQueryRequest request = new AlipayUserCertifyOpenQueryRequest();
//设置certifyId
AlipayUserCertifyOpenQueryRequest request = new AlipayUserCertifyOpenQueryRequest ();
JSONObject bizContentObj = new JSONObject();
//certifyId是初始化接口返回
bizContentObj.put("certify_id", certify_id);
bizContentObj.put("certify_id", certify_id);//本次申请操作的唯一标识,由开放认证初始化接口调用后生成
request.setBizContent(bizContentObj.toString());
AlipayUserCertifyOpenQueryResponse response = alipayClient.execute(request);
if(response.isSuccess()){
System.out.println("开始认证服务调用成功");
String certifyUrl = response.getBody();
response.getPassed();
response.isSuccess();
return alipayClient.execute(request);
//执行后续流程...
} else {
System.out.println("调用失败");
}
return null;
}
... ...
package com.yohoufo.user.service;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
... ... @@ -22,4 +23,12 @@ public interface ICertificationService {
* @return 认证结果
*/
AuthorizeResultRespVO beginCertificate(RealNameAuthorizeReqVO realNameAuthorizeReqVO);
/**
* 身份认证记录查询
* @param reqVO
* @return
*/
ApiResponse queryUserCertify(RealNameAuthorizeReqVO reqVO);
}
... ...
package com.yohoufo.user.service.impl;
import com.alipay.api.response.AlipayUserCertifyOpenQueryResponse;
import com.alipay.api.response.ZhimaCustomerCertificationQueryResponse;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.constant.CertPhotoEnum;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.user.IZhiMaCertDao;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.user.helper.AlipayCertificationHelper;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import com.yohoufo.user.service.ICertificationService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -26,6 +31,7 @@ public class CertificationServiceImpl implements ICertificationService {
private final Logger logger = LoggerFactory.getLogger(CertificationServiceImpl.class);
@Autowired
private IZhiMaCertDao zhiMaCertDao;
... ... @@ -76,6 +82,37 @@ public class CertificationServiceImpl implements ICertificationService {
return null;
}
@Override
public ApiResponse queryUserCertify(RealNameAuthorizeReqVO reqVO) {
try {
logger.info("queryUserCertify: enter. reqVO is {}", reqVO);
//(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 = AlipayCertificationHelper.alipayCertifyResult(zhiMaCert.getBizNo());
logger.info("queryUserCertify: queryUserCert by alipay success. reqVO is {}, certResult is {}", reqVO, response);
if(response.isSuccess() && "T".equals(response.getPassed().get(0))){
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<>(true);
}else{
String errorMsg = response.getSubMsg();//认证不通过可能是出现异常情况
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, "查询身份认证结果失败");
}
}
}
... ...