Authored by 匡佳华

支付宝身份认证记录查询

@@ -94,6 +94,28 @@ public class CertificationController { @@ -94,6 +94,28 @@ public class CertificationController {
94 return apiResponse; 94 return apiResponse;
95 } 95 }
96 96
  97 + /**
  98 + * 身份认证记录查询
  99 + * @param reqVO
  100 + * @return true: 通过, false: 不通过
  101 + * @throws GatewayException
  102 + */
  103 + @RequestMapping(params = "method=ufo.user.alipayCertifyResultQuery")
  104 + public ApiResponse alipayCertifyResultQuery(RealNameAuthorizeReqVO reqVO) throws GatewayException {
  105 + logger.info("CertificationController.alipayCertifyResultQuery: Enter. RealNameAuthorizeReqVO is {}", reqVO);
  106 + //(1) 校验请求的参数
  107 + if (reqVO == null || reqVO.getUid() <= 0){
  108 + throw new GatewayException(400, "参数错误,uid不能为空!");
  109 + }
  110 + if(StringUtils.isBlank(reqVO.getZhiMaBizNo())){
  111 + throw new GatewayException(400, "参数错误,zhiMaBizNo不能为空!");
  112 + }
  113 + //(2) 调用支付宝接口查询认证结果
  114 + ApiResponse result = certificationService.queryUserCertify(reqVO);
  115 + logger.info("CertificationController.alipayCertifyResultQuery: End. result is {}", result);
  116 + return result;
  117 + }
  118 +
97 119
98 120
99 121
@@ -7,9 +7,11 @@ import com.alipay.api.DefaultAlipayClient; @@ -7,9 +7,11 @@ import com.alipay.api.DefaultAlipayClient;
7 import com.alipay.api.request.AlipayUserCertifyOpenCertifyRequest; 7 import com.alipay.api.request.AlipayUserCertifyOpenCertifyRequest;
8 import com.alipay.api.request.AlipayUserCertifyOpenInitializeRequest; 8 import com.alipay.api.request.AlipayUserCertifyOpenInitializeRequest;
9 import com.alipay.api.request.AlipayUserCertifyOpenQueryRequest; 9 import com.alipay.api.request.AlipayUserCertifyOpenQueryRequest;
  10 +import com.alipay.api.request.ZhimaCustomerCertificationQueryRequest;
10 import com.alipay.api.response.AlipayUserCertifyOpenCertifyResponse; 11 import com.alipay.api.response.AlipayUserCertifyOpenCertifyResponse;
11 import com.alipay.api.response.AlipayUserCertifyOpenInitializeResponse; 12 import com.alipay.api.response.AlipayUserCertifyOpenInitializeResponse;
12 import com.alipay.api.response.AlipayUserCertifyOpenQueryResponse; 13 import com.alipay.api.response.AlipayUserCertifyOpenQueryResponse;
  14 +import com.alipay.api.response.ZhimaCustomerCertificationQueryResponse;
13 15
14 import java.util.UUID; 16 import java.util.UUID;
15 17
@@ -112,29 +114,17 @@ public class AlipayCertificationHelper { @@ -112,29 +114,17 @@ public class AlipayCertificationHelper {
112 return null; 114 return null;
113 } 115 }
114 116
115 - public static String alipayCertifyResult(String certify_id) throws AlipayApiException { 117 + public static AlipayUserCertifyOpenQueryResponse alipayCertifyResult(String certify_id) throws AlipayApiException {
116 //获取alipay client 118 //获取alipay client
117 AlipayClient alipayClient = new DefaultAlipayClient(ALI_URL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE); 119 AlipayClient alipayClient = new DefaultAlipayClient(ALI_URL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE);
118 - AlipayUserCertifyOpenQueryRequest request = new AlipayUserCertifyOpenQueryRequest();  
119 120
120 - //设置certifyId 121 + AlipayUserCertifyOpenQueryRequest request = new AlipayUserCertifyOpenQueryRequest ();
121 JSONObject bizContentObj = new JSONObject(); 122 JSONObject bizContentObj = new JSONObject();
122 - //certifyId是初始化接口返回  
123 - bizContentObj.put("certify_id", certify_id); 123 + bizContentObj.put("certify_id", certify_id);//本次申请操作的唯一标识,由开放认证初始化接口调用后生成
124 request.setBizContent(bizContentObj.toString()); 124 request.setBizContent(bizContentObj.toString());
125 125
126 - AlipayUserCertifyOpenQueryResponse response = alipayClient.execute(request);  
127 - if(response.isSuccess()){  
128 - System.out.println("开始认证服务调用成功");  
129 - String certifyUrl = response.getBody();  
130 - response.getPassed();  
131 - response.isSuccess(); 126 + return alipayClient.execute(request);
132 127
133 - //执行后续流程...  
134 - } else {  
135 - System.out.println("调用失败");  
136 - }  
137 - return null;  
138 } 128 }
139 129
140 130
1 package com.yohoufo.user.service; 1 package com.yohoufo.user.service;
2 2
  3 +import com.yoho.tools.common.beans.ApiResponse;
3 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO; 4 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
4 import com.yohoufo.dal.user.model.ZhiMaCert; 5 import com.yohoufo.dal.user.model.ZhiMaCert;
5 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO; 6 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
@@ -22,4 +23,12 @@ public interface ICertificationService { @@ -22,4 +23,12 @@ public interface ICertificationService {
22 * @return 认证结果 23 * @return 认证结果
23 */ 24 */
24 AuthorizeResultRespVO beginCertificate(RealNameAuthorizeReqVO realNameAuthorizeReqVO); 25 AuthorizeResultRespVO beginCertificate(RealNameAuthorizeReqVO realNameAuthorizeReqVO);
  26 +
  27 + /**
  28 + * 身份认证记录查询
  29 + * @param reqVO
  30 + * @return
  31 + */
  32 + ApiResponse queryUserCertify(RealNameAuthorizeReqVO reqVO);
  33 +
25 } 34 }
1 package com.yohoufo.user.service.impl; 1 package com.yohoufo.user.service.impl;
2 2
  3 +import com.alipay.api.response.AlipayUserCertifyOpenQueryResponse;
  4 +import com.alipay.api.response.ZhimaCustomerCertificationQueryResponse;
  5 +import com.yoho.tools.common.beans.ApiResponse;
3 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO; 6 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
4 import com.yohoufo.common.constant.CertPhotoEnum; 7 import com.yohoufo.common.constant.CertPhotoEnum;
5 import com.yohoufo.common.exception.UfoServiceException; 8 import com.yohoufo.common.exception.UfoServiceException;
6 import com.yohoufo.dal.user.IZhiMaCertDao; 9 import com.yohoufo.dal.user.IZhiMaCertDao;
7 import com.yohoufo.dal.user.model.ZhiMaCert; 10 import com.yohoufo.dal.user.model.ZhiMaCert;
  11 +import com.yohoufo.user.helper.AlipayCertificationHelper;
8 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO; 12 import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
9 import com.yohoufo.user.service.ICertificationService; 13 import com.yohoufo.user.service.ICertificationService;
  14 +import org.apache.commons.lang3.StringUtils;
10 import org.slf4j.Logger; 15 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 16 import org.slf4j.LoggerFactory;
12 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +31,7 @@ public class CertificationServiceImpl implements ICertificationService { @@ -26,6 +31,7 @@ public class CertificationServiceImpl implements ICertificationService {
26 31
27 private final Logger logger = LoggerFactory.getLogger(CertificationServiceImpl.class); 32 private final Logger logger = LoggerFactory.getLogger(CertificationServiceImpl.class);
28 33
  34 +
29 @Autowired 35 @Autowired
30 private IZhiMaCertDao zhiMaCertDao; 36 private IZhiMaCertDao zhiMaCertDao;
31 37
@@ -76,6 +82,37 @@ public class CertificationServiceImpl implements ICertificationService { @@ -76,6 +82,37 @@ public class CertificationServiceImpl implements ICertificationService {
76 return null; 82 return null;
77 } 83 }
78 84
  85 + @Override
  86 + public ApiResponse queryUserCertify(RealNameAuthorizeReqVO reqVO) {
  87 + try {
  88 + logger.info("queryUserCertify: enter. reqVO is {}", reqVO);
  89 + //(1) 根据 bizNo 查询认证信息是否存在
  90 + ZhiMaCert zhiMaCert = zhiMaCertDao.selectByBizNo(reqVO.getZhiMaBizNo());
  91 + if (zhiMaCert == null || StringUtils.isEmpty(zhiMaCert.getBizNo())) {
  92 + logger.warn("queryUserCertify: certInfo is null. reqVO is {}", reqVO);
  93 + throw new UfoServiceException(400, "未找到身份认证信息!");
  94 + }
  95 + //(2) 身份认证结果获取(调用支付宝接口)并更新
  96 + AlipayUserCertifyOpenQueryResponse response = AlipayCertificationHelper.alipayCertifyResult(zhiMaCert.getBizNo());
  97 + logger.info("queryUserCertify: queryUserCert by alipay success. reqVO is {}, certResult is {}", reqVO, response);
  98 + if(response.isSuccess() && "T".equals(response.getPassed().get(0))){
  99 + int updateCount = zhiMaCertDao.updateValidStatusByPrimaryKey(zhiMaCert.getId());
  100 + if(updateCount < 1){
  101 + logger.warn("queryUserCertify: update certResult fail. reqVO is {}", reqVO);
  102 + throw new UfoServiceException(400, "更新身份认证结果失败!");
  103 + }
  104 + logger.info("queryUserCertify: userCert pass. reqVO is {}, certResult is {}", reqVO, response);
  105 + return new ApiResponse<>(true);
  106 + }else{
  107 + String errorMsg = response.getSubMsg();//认证不通过可能是出现异常情况
  108 + logger.info("queryUserCertify: userCert notPass. reqVO is {}, certResult is {}", reqVO, response);
  109 + return new ApiResponse<>(400, StringUtils.isEmpty(errorMsg) ? "身份认证不通过" : errorMsg ,false);
  110 + }
  111 + }catch(Exception e){
  112 + logger.warn("queryUserCertify: error. reqVO is {}, e is {}", reqVO, e);
  113 + throw new UfoServiceException(400, "查询身份认证结果失败");
  114 + }
  115 + }
79 116
80 117
81 } 118 }