Showing
6 changed files
with
171 additions
and
163 deletions
1 | package com.yohoufo.dal.user.model; | 1 | package com.yohoufo.dal.user.model; |
2 | 2 | ||
3 | +import lombok.Data; | ||
4 | + | ||
3 | /** | 5 | /** |
4 | * 访问银联接口,认证记录日志表 | 6 | * 访问银联接口,认证记录日志表 |
5 | */ | 7 | */ |
8 | +@Data | ||
6 | public class UserAuthorizeHistory { | 9 | public class UserAuthorizeHistory { |
7 | //主键 | 10 | //主键 |
8 | private Integer id; | 11 | private Integer id; |
@@ -19,79 +22,14 @@ public class UserAuthorizeHistory { | @@ -19,79 +22,14 @@ public class UserAuthorizeHistory { | ||
19 | //银联返回内容 | 22 | //银联返回内容 |
20 | private String responseContent; | 23 | private String responseContent; |
21 | 24 | ||
25 | + //系统错误码、错误信息 :0000 – 成功 | ||
26 | + private String backErrorCode; | ||
27 | + private String backErrorInfo; | ||
28 | + //一级错误码,00 和 01 类型是收费的 | ||
29 | + private String firstErrorCode; | ||
30 | + | ||
22 | private long createTime; | 31 | private long createTime; |
23 | 32 | ||
24 | private long updateTime; | 33 | private long updateTime; |
25 | 34 | ||
26 | - public Integer getId() { | ||
27 | - return id; | ||
28 | - } | ||
29 | - | ||
30 | - public void setId(Integer id) { | ||
31 | - this.id = id; | ||
32 | - } | ||
33 | - | ||
34 | - public Integer getUid() { | ||
35 | - return uid; | ||
36 | - } | ||
37 | - | ||
38 | - public void setUid(Integer uid) { | ||
39 | - this.uid = uid; | ||
40 | - } | ||
41 | - | ||
42 | - public String getCardNo() { | ||
43 | - return cardNo; | ||
44 | - } | ||
45 | - | ||
46 | - public void setCardNo(String cardNo) { | ||
47 | - this.cardNo = cardNo; | ||
48 | - } | ||
49 | - | ||
50 | - public String getCertNo() { | ||
51 | - return certNo; | ||
52 | - } | ||
53 | - | ||
54 | - public void setCertNo(String certNo) { | ||
55 | - this.certNo = certNo; | ||
56 | - } | ||
57 | - | ||
58 | - public String getCertName() { | ||
59 | - return certName; | ||
60 | - } | ||
61 | - | ||
62 | - public void setCertName(String certName) { | ||
63 | - this.certName = certName; | ||
64 | - } | ||
65 | - | ||
66 | - public Integer getResponseCode() { | ||
67 | - return responseCode; | ||
68 | - } | ||
69 | - | ||
70 | - public void setResponseCode(Integer responseCode) { | ||
71 | - this.responseCode = responseCode; | ||
72 | - } | ||
73 | - | ||
74 | - public String getResponseContent() { | ||
75 | - return responseContent; | ||
76 | - } | ||
77 | - | ||
78 | - public void setResponseContent(String responseContent) { | ||
79 | - this.responseContent = responseContent; | ||
80 | - } | ||
81 | - | ||
82 | - public long getCreateTime() { | ||
83 | - return createTime; | ||
84 | - } | ||
85 | - | ||
86 | - public void setCreateTime(long createTime) { | ||
87 | - this.createTime = createTime; | ||
88 | - } | ||
89 | - | ||
90 | - public long getUpdateTime() { | ||
91 | - return updateTime; | ||
92 | - } | ||
93 | - | ||
94 | - public void setUpdateTime(long updateTime) { | ||
95 | - this.updateTime = updateTime; | ||
96 | - } | ||
97 | } | 35 | } |
1 | package com.yohoufo.dal.user.model; | 1 | package com.yohoufo.dal.user.model; |
2 | + | ||
3 | +import lombok.Data; | ||
4 | + | ||
2 | /** | 5 | /** |
3 | * 实名认证信息表-具体认证信息 | 6 | * 实名认证信息表-具体认证信息 |
4 | * 提供给前端查询用 | 7 | * 提供给前端查询用 |
5 | */ | 8 | */ |
9 | +@Data | ||
6 | public class UserAuthorizeInfo { | 10 | public class UserAuthorizeInfo { |
7 | //主键 | 11 | //主键 |
8 | private Integer id; | 12 | private Integer id; |
@@ -20,67 +24,4 @@ public class UserAuthorizeInfo { | @@ -20,67 +24,4 @@ public class UserAuthorizeInfo { | ||
20 | 24 | ||
21 | private long updateTime; | 25 | private long updateTime; |
22 | 26 | ||
23 | - public Integer getId() { | ||
24 | - return id; | ||
25 | - } | ||
26 | - | ||
27 | - public void setId(Integer id) { | ||
28 | - this.id = id; | ||
29 | - } | ||
30 | - | ||
31 | - public Integer getUid() { | ||
32 | - return uid; | ||
33 | - } | ||
34 | - | ||
35 | - public void setUid(Integer uid) { | ||
36 | - this.uid = uid; | ||
37 | - } | ||
38 | - | ||
39 | - public Integer getValidStatus() { | ||
40 | - return validStatus; | ||
41 | - } | ||
42 | - | ||
43 | - public void setValidStatus(Integer validStatus) { | ||
44 | - this.validStatus = validStatus; | ||
45 | - } | ||
46 | - | ||
47 | - public String getCardNo() { | ||
48 | - return cardNo; | ||
49 | - } | ||
50 | - | ||
51 | - public void setCardNo(String cardNo) { | ||
52 | - this.cardNo = cardNo; | ||
53 | - } | ||
54 | - | ||
55 | - public String getCertNo() { | ||
56 | - return certNo; | ||
57 | - } | ||
58 | - | ||
59 | - public void setCertNo(String certNo) { | ||
60 | - this.certNo = certNo; | ||
61 | - } | ||
62 | - | ||
63 | - public String getCertName() { | ||
64 | - return certName; | ||
65 | - } | ||
66 | - | ||
67 | - public void setCertName(String certName) { | ||
68 | - this.certName = certName; | ||
69 | - } | ||
70 | - | ||
71 | - public long getCreateTime() { | ||
72 | - return createTime; | ||
73 | - } | ||
74 | - | ||
75 | - public void setCreateTime(long createTime) { | ||
76 | - this.createTime = createTime; | ||
77 | - } | ||
78 | - | ||
79 | - public long getUpdateTime() { | ||
80 | - return updateTime; | ||
81 | - } | ||
82 | - | ||
83 | - public void setUpdateTime(long updateTime) { | ||
84 | - this.updateTime = updateTime; | ||
85 | - } | ||
86 | } | 27 | } |
@@ -9,6 +9,9 @@ | @@ -9,6 +9,9 @@ | ||
9 | <result column="cert_name" property="certName" jdbcType="VARCHAR" /> | 9 | <result column="cert_name" property="certName" jdbcType="VARCHAR" /> |
10 | <result column="response_code" property="responseCode" jdbcType="INTEGER" /> | 10 | <result column="response_code" property="responseCode" jdbcType="INTEGER" /> |
11 | <result column="response_content" property="responseContent" jdbcType="VARCHAR" /> | 11 | <result column="response_content" property="responseContent" jdbcType="VARCHAR" /> |
12 | + <result column="back_error_code" property="backErrorCode" jdbcType="VARCHAR" /> | ||
13 | + <result column="back_error_info" property="backErrorInfo" jdbcType="VARCHAR" /> | ||
14 | + <result column="first_error_code" property="firstErrorCode" jdbcType="VARCHAR" /> | ||
12 | <result column="create_time" property="createTime" jdbcType="INTEGER" /> | 15 | <result column="create_time" property="createTime" jdbcType="INTEGER" /> |
13 | <result column="update_time" property="updateTime" jdbcType="INTEGER" /> | 16 | <result column="update_time" property="updateTime" jdbcType="INTEGER" /> |
14 | </resultMap> | 17 | </resultMap> |
@@ -19,9 +22,10 @@ | @@ -19,9 +22,10 @@ | ||
19 | 22 | ||
20 | <insert id="insert" parameterType="com.yohoufo.dal.user.model.UserAuthorizeHistory" > | 23 | <insert id="insert" parameterType="com.yohoufo.dal.user.model.UserAuthorizeHistory" > |
21 | insert into authorize_history (uid, card_no, cert_no, cert_name, response_code , | 24 | insert into authorize_history (uid, card_no, cert_no, cert_name, response_code , |
22 | - response_content ,create_time, update_time) | 25 | + response_content ,back_error_code,back_error_info,first_error_code,create_time, update_time) |
23 | values (#{uid,jdbcType=INTEGER},#{cardNo,jdbcType=VARCHAR},#{certNo,jdbcType=VARCHAR}, | 26 | values (#{uid,jdbcType=INTEGER},#{cardNo,jdbcType=VARCHAR},#{certNo,jdbcType=VARCHAR}, |
24 | #{certName,jdbcType=VARCHAR},#{responseCode,jdbcType=INTEGER},#{responseContent,jdbcType=VARCHAR}, | 27 | #{certName,jdbcType=VARCHAR},#{responseCode,jdbcType=INTEGER},#{responseContent,jdbcType=VARCHAR}, |
28 | + #{backErrorCode,jdbcType=VARCHAR},#{backErrorInfo,jdbcType=VARCHAR},#{firstErrorCode,jdbcType=VARCHAR}, | ||
25 | #{createTime,jdbcType=BIGINT},#{updateTime,jdbcType=BIGINT}) | 29 | #{createTime,jdbcType=BIGINT},#{updateTime,jdbcType=BIGINT}) |
26 | </insert> | 30 | </insert> |
27 | 31 |
1 | +package com.yohoufo.user.common; | ||
2 | + | ||
3 | +/** | ||
4 | + * 银联定义的返回应答码 | ||
5 | + * 如有变化,具体以银联文档为准 | ||
6 | + */ | ||
7 | +public enum EnumBankBackCode { | ||
8 | + //定义 | ||
9 | + code_0000("0000","验证一致","00","验证一致"), | ||
10 | + code_2314("2314","发卡行无此卡号","01","验证不一致"), | ||
11 | + code_2316("2316","发卡行返回该卡状态不正常,建议持卡人与发卡行联系","01","验证不一致"), | ||
12 | + code_2319("2319","验证不一致","01","验证不一致"), | ||
13 | + code_2320("2320","发卡行返回该卡密码错次数超限,建议持卡人与发卡行联系","01","验证不一致"), | ||
14 | + code_2344("2344","发卡行返回该卡未预留手机号,建议持卡人与发卡行联系","01","验证不一致"), | ||
15 | + code_2321("2321","不支持发现卡验证交易","02","不支持验证"), | ||
16 | + code_2325("2325","发卡行返回该卡不支持验证,建议持卡人与发卡行联系","02","不支持验证"), | ||
17 | + code_2334("2334","发卡行返回该卡验证次数已超限,请明日再试","02","不支持验证"), | ||
18 | + code_2346("2346","建行卡不支持卡号+手机号两要素组合验证","02","不支持验证"), | ||
19 | + code_5000("5000","未知商户,不予通过","02","不支持验证"), | ||
20 | + code_5101("5101","该卡交易过于频繁,请稍后重试","02","不支持验证"), | ||
21 | + code_5102("5102","该证件号交易过于频繁,请稍后重试","02","不支持验证"), | ||
22 | + code_5103("5103","该卡今日验证失败次数过多,请明日重试","02","不支持验证"), | ||
23 | + code_5104("5104","该证件号今日验证失败次数过多,请明日重试","02","不支持验证"), | ||
24 | + code_5105("5105","短期内有同卡重复交易,请稍后重试","02","不支持验证"), | ||
25 | + code_5106("5106","该卡今日验证次数过多,请明日重试","02","不支持验证"), | ||
26 | + code_5107("5107","请取得个人授权","02","不支持验证"), | ||
27 | + code_5108("5108","当日验证次数已达最大值,请明日再试","02","不支持验证"), | ||
28 | + code_4001("4001","无效卡","03","验证要素格式有误"), | ||
29 | + code_4002("4002","无效证件类型","03","验证要素格式有误"), | ||
30 | + code_4003("4003","无效证件号","03","验证要素格式有误"), | ||
31 | + code_4004("4004","无效手机号","03","验证要素格式有误"), | ||
32 | + code_4005("4005","无效姓名","03","验证要素格式有误"), | ||
33 | + code_4006("4006","多种要素格式错误","03","验证要素格式有误"), | ||
34 | + code_1302("1302","发卡行响应超时,请稍后重试","04","系统异常"), | ||
35 | + code_1399("1399","发卡行系统异常,请稍后重试","04","系统异常"), | ||
36 | + code_2208("2208","渠道方系统异常,请稍后重试","04","系统异常"), | ||
37 | + code_2329("2329","系统异常,请稍后重试","04","系统异常") | ||
38 | + ; | ||
39 | + | ||
40 | + // 成员变量 | ||
41 | + //应答码细分 | ||
42 | + private String secondCode; | ||
43 | + private String secondCodeDesc; | ||
44 | + | ||
45 | + // 应答码 00 验证一致(收费) 和 01 验证不一致(收费) ,其余情况不收费 | ||
46 | + private String firstCode; | ||
47 | + private String firstCodeDesc; | ||
48 | + | ||
49 | + //构造函数 | ||
50 | + EnumBankBackCode(String secondCode,String secondCodeDesc,String firstCode,String firstCodeDesc){ | ||
51 | + this.secondCode = secondCode; | ||
52 | + this.secondCodeDesc = secondCodeDesc; | ||
53 | + this.firstCode = firstCode; | ||
54 | + this.firstCodeDesc = firstCodeDesc; | ||
55 | + } | ||
56 | + | ||
57 | + public static String getFirstCodeBySecondCode(String secondCode){ | ||
58 | + if(secondCode==null){ | ||
59 | + return ""; | ||
60 | + } | ||
61 | + for(EnumBankBackCode backCode:EnumBankBackCode.values()){ | ||
62 | + if(secondCode.equals(backCode.secondCode)){ | ||
63 | + return backCode.firstCode; | ||
64 | + } | ||
65 | + } | ||
66 | + return ""; | ||
67 | + } | ||
68 | + | ||
69 | + | ||
70 | +} |
@@ -21,7 +21,7 @@ public class RestTemplateForBank { | @@ -21,7 +21,7 @@ public class RestTemplateForBank { | ||
21 | */ | 21 | */ |
22 | @Bean | 22 | @Bean |
23 | public RestTemplate authorizeBankRestTemplate(){ | 23 | public RestTemplate authorizeBankRestTemplate(){ |
24 | - ResponseErrorHandler responseErrorHandler = new ResponseErrorHandler() { | 24 | + /* ResponseErrorHandler responseErrorHandler = new ResponseErrorHandler() { |
25 | @Override | 25 | @Override |
26 | public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException { | 26 | public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException { |
27 | int statusCode = getHttpStatusResponseCode(clientHttpResponse); | 27 | int statusCode = getHttpStatusResponseCode(clientHttpResponse); |
@@ -46,7 +46,7 @@ public class RestTemplateForBank { | @@ -46,7 +46,7 @@ public class RestTemplateForBank { | ||
46 | return 400; | 46 | return 400; |
47 | } | 47 | } |
48 | } | 48 | } |
49 | - }; | 49 | + };*/ |
50 | 50 | ||
51 | 51 | ||
52 | HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(); | 52 | HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(); |
@@ -55,7 +55,7 @@ public class RestTemplateForBank { | @@ -55,7 +55,7 @@ public class RestTemplateForBank { | ||
55 | httpRequestFactory.setReadTimeout(500); | 55 | httpRequestFactory.setReadTimeout(500); |
56 | 56 | ||
57 | RestTemplate restTemplate= new RestTemplate(httpRequestFactory); | 57 | RestTemplate restTemplate= new RestTemplate(httpRequestFactory); |
58 | - restTemplate.setErrorHandler(responseErrorHandler); | 58 | + //restTemplate.setErrorHandler(responseErrorHandler); |
59 | return restTemplate; | 59 | return restTemplate; |
60 | } | 60 | } |
61 | } | 61 | } |
@@ -8,10 +8,12 @@ import com.yohoufo.dal.user.IUserAuthorizeInfoDao; | @@ -8,10 +8,12 @@ import com.yohoufo.dal.user.IUserAuthorizeInfoDao; | ||
8 | import com.yohoufo.dal.user.model.UserAuthorizeHistory; | 8 | import com.yohoufo.dal.user.model.UserAuthorizeHistory; |
9 | import com.yohoufo.dal.user.model.UserAuthorizeInfo; | 9 | import com.yohoufo.dal.user.model.UserAuthorizeInfo; |
10 | import com.yohoufo.user.cache.RedisValueCache; | 10 | import com.yohoufo.user.cache.RedisValueCache; |
11 | +import com.yohoufo.user.common.EnumBankBackCode; | ||
11 | import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO; | 12 | import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO; |
12 | import com.yohoufo.user.responseVO.AuthorizeResultRespVO; | 13 | import com.yohoufo.user.responseVO.AuthorizeResultRespVO; |
13 | import com.yohoufo.user.service.IRealNameAuthorizeService; | 14 | import com.yohoufo.user.service.IRealNameAuthorizeService; |
14 | import com.yohoufo.user.service.risk.GraphVerifyService; | 15 | import com.yohoufo.user.service.risk.GraphVerifyService; |
16 | +import lombok.Data; | ||
15 | import net.sf.json.JSONObject; | 17 | import net.sf.json.JSONObject; |
16 | import org.apache.commons.codec.binary.Base64; | 18 | import org.apache.commons.codec.binary.Base64; |
17 | import org.apache.commons.codec.digest.DigestUtils; | 19 | import org.apache.commons.codec.digest.DigestUtils; |
@@ -20,12 +22,14 @@ import org.slf4j.Logger; | @@ -20,12 +22,14 @@ import org.slf4j.Logger; | ||
20 | import org.slf4j.LoggerFactory; | 22 | import org.slf4j.LoggerFactory; |
21 | import org.springframework.beans.factory.annotation.Autowired; | 23 | import org.springframework.beans.factory.annotation.Autowired; |
22 | import org.springframework.http.HttpEntity; | 24 | import org.springframework.http.HttpEntity; |
23 | -import org.springframework.http.HttpStatus; | ||
24 | import org.springframework.http.MediaType; | 25 | import org.springframework.http.MediaType; |
25 | import org.springframework.http.ResponseEntity; | 26 | import org.springframework.http.ResponseEntity; |
26 | import org.springframework.stereotype.Service; | 27 | import org.springframework.stereotype.Service; |
27 | import org.springframework.util.LinkedMultiValueMap; | 28 | import org.springframework.util.LinkedMultiValueMap; |
28 | import org.springframework.util.MultiValueMap; | 29 | import org.springframework.util.MultiValueMap; |
30 | +import org.springframework.web.client.HttpClientErrorException; | ||
31 | +import org.springframework.web.client.HttpServerErrorException; | ||
32 | +import org.springframework.web.client.RestClientException; | ||
29 | import org.springframework.web.client.RestTemplate; | 33 | import org.springframework.web.client.RestTemplate; |
30 | 34 | ||
31 | import javax.annotation.Resource; | 35 | import javax.annotation.Resource; |
@@ -136,14 +140,12 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { | @@ -136,14 +140,12 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { | ||
136 | //根据报文体,生成HTTP报文头的认证内容 (open-body-sig 方式) | 140 | //根据报文体,生成HTTP报文头的认证内容 (open-body-sig 方式) |
137 | String authorizationContentByOpenBodySig=generateAuthorizationByOpenBodySig(msgContentParams); | 141 | String authorizationContentByOpenBodySig=generateAuthorizationByOpenBodySig(msgContentParams); |
138 | //请求返回 | 142 | //请求返回 |
139 | - ResponseEntity<Object> responseEntity = postRequest(msgContentParams,authorizationContentByOpenBodySig); | 143 | + PostBankResult responseResult = postRequest(msgContentParams,authorizationContentByOpenBodySig); |
140 | 144 | ||
141 | //返回结果处理:请求成功入认证信息库,请求失败记录的redis,后续超过一定次数则开启验证码 | 145 | //返回结果处理:请求成功入认证信息库,请求失败记录的redis,后续超过一定次数则开启验证码 |
142 | - int responseCode=responseEntity.getStatusCodeValue(); | ||
143 | - String responseContent=String.valueOf(responseEntity.getBody()); | ||
144 | - ApiResponse apiResponse=new ApiResponse(400,responseContent,null); | 146 | + ApiResponse apiResponse=new ApiResponse(400,responseResult.getErrInfo(),null); |
145 | long ts=getLocalDateTime().toEpochSecond(ZoneOffset.of("+8")); | 147 | long ts=getLocalDateTime().toEpochSecond(ZoneOffset.of("+8")); |
146 | - if(responseCode==200){ | 148 | + if(responseResult.isSucFlag()){ |
147 | UserAuthorizeInfo userAuthorizeInfo =new UserAuthorizeInfo(); | 149 | UserAuthorizeInfo userAuthorizeInfo =new UserAuthorizeInfo(); |
148 | try{ | 150 | try{ |
149 | userAuthorizeInfo.setUid(uid); | 151 | userAuthorizeInfo.setUid(uid); |
@@ -166,7 +168,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { | @@ -166,7 +168,7 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { | ||
166 | } | 168 | } |
167 | 169 | ||
168 | //访问银联接口记录日志 | 170 | //访问银联接口记录日志 |
169 | - recordHistory(uid,cardNo,certNo,name,responseCode,responseContent,ts); | 171 | + recordHistory(uid,cardNo,certNo,name,responseResult,ts); |
170 | 172 | ||
171 | return apiResponse; | 173 | return apiResponse; |
172 | } | 174 | } |
@@ -211,51 +213,104 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { | @@ -211,51 +213,104 @@ public class RealNameAuthorizeServiceImpl implements IRealNameAuthorizeService { | ||
211 | * 请求银联接口,获取返回信息 | 213 | * 请求银联接口,获取返回信息 |
212 | * 捕获所有异常 | 214 | * 捕获所有异常 |
213 | */ | 215 | */ |
214 | - private ResponseEntity<Object> postRequest(JSONObject msgContentParams,String authorizationContentByOpenBodySig){ | ||
215 | - ResponseEntity<Object> responseEntity=new ResponseEntity<>(HttpStatus.NOT_EXTENDED); | 216 | + private PostBankResult postRequest(JSONObject msgContentParams,String authorizationContentByOpenBodySig){ |
217 | + PostBankResult result=new PostBankResult(); | ||
216 | try{ | 218 | try{ |
217 | //组成post的请求参数 | 219 | //组成post的请求参数 |
218 | JSONObject dataParams=new JSONObject(); | 220 | JSONObject dataParams=new JSONObject(); |
219 | dataParams.put("data",msgContentParams); | 221 | dataParams.put("data",msgContentParams); |
220 | 222 | ||
221 | - //return RealNameAuthorizePostBankUtil.postByhttpClient(authorizationContentByOpenBodySig,dataParams); | ||
222 | - | ||
223 | - //headers | ||
224 | - /* HttpHeaders headers = new HttpHeaders(); | ||
225 | - MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); | ||
226 | - headers.setContentType(type); | ||
227 | - headers.add("Accept", MediaType.APPLICATION_JSON.toString()); | ||
228 | - headers.add("Authorization",authorizationContentByOpenBodySig);*/ | ||
229 | - | 223 | + //header |
230 | MultiValueMap<String, String> headers = new LinkedMultiValueMap(); | 224 | MultiValueMap<String, String> headers = new LinkedMultiValueMap(); |
231 | headers.set("Content-Type", "application/json; charset=UTF-8"); | 225 | headers.set("Content-Type", "application/json; charset=UTF-8"); |
232 | headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); | 226 | headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); |
233 | headers.set("Authorization",authorizationContentByOpenBodySig); | 227 | headers.set("Authorization",authorizationContentByOpenBodySig); |
234 | - | ||
235 | //body | 228 | //body |
236 | HttpEntity<JSONObject> bodyEntity = new HttpEntity<>(dataParams, headers); | 229 | HttpEntity<JSONObject> bodyEntity = new HttpEntity<>(dataParams, headers); |
237 | logger.info("RealNameAuthorizeServiceImpl authorizeRealNameWithBank request message {} ,headers {} ,body {}",msgContentParams,headers,bodyEntity); | 230 | logger.info("RealNameAuthorizeServiceImpl authorizeRealNameWithBank request message {} ,headers {} ,body {}",msgContentParams,headers,bodyEntity); |
238 | //post | 231 | //post |
239 | - responseEntity = restTemplate.postForEntity(requestUrl, bodyEntity, Object.class); | 232 | + ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(requestUrl, bodyEntity, JSONObject.class); |
240 | logger.info("RealNameAuthorizeServiceImpl authorizeRealNameWithBank response entity {} ",responseEntity); | 233 | logger.info("RealNameAuthorizeServiceImpl authorizeRealNameWithBank response entity {} ",responseEntity); |
234 | + //处理结果 | ||
235 | + JSONObject jo=responseEntity.getBody(); | ||
236 | + if(jo==null){ | ||
237 | + result.setSucFlag(false); | ||
238 | + result.setBackMsg("请求银联返回内容为空"); | ||
239 | + return result; | ||
240 | + } | ||
241 | + result.setBackMsg(jo.toString()); | ||
242 | + result.setStatusCode(responseEntity.getStatusCodeValue()); | ||
243 | + //实名认证成功的应答码:"0000" | ||
244 | + if(responseEntity.getStatusCodeValue()==200&&jo!=null&&"0000".equals(jo.getString("errCode"))){ | ||
245 | + result.setSucFlag(true); | ||
246 | + result.setErrCode("0000"); | ||
247 | + result.setErrInfo("请求银联实名认证成功"); | ||
248 | + }else{ | ||
249 | + result.setSucFlag(false); | ||
250 | + result.setErrCode(jo==null?"":jo.getString("errCode")); | ||
251 | + result.setErrInfo(jo==null?"":jo.getString("errInfo")); | ||
252 | + } | ||
241 | }catch (Exception e){ | 253 | }catch (Exception e){ |
242 | - logger.error("RealNameAuthorizeServiceImpl authorizeRealNameWithBank response entity {} ,error",responseEntity,e); | 254 | + logger.error("RealNameAuthorizeServiceImpl authorizeRealNameWithBank response msgContentParams {} ,error",msgContentParams,e); |
255 | + | ||
256 | + //记录错误码 | ||
257 | + result.setSucFlag(false); | ||
258 | + if(e instanceof HttpClientErrorException){ | ||
259 | + HttpClientErrorException errorException=(HttpClientErrorException)e; | ||
260 | + result.setStatusCode(errorException.getStatusCode().value()); | ||
261 | + result.setBackMsg(errorException.getResponseBodyAsString()); | ||
262 | + try{ | ||
263 | + JSONObject jo=JSONObject.fromObject(result.getBackMsg()); | ||
264 | + result.setErrCode(jo==null?"":jo.getString("errCode")); | ||
265 | + result.setErrInfo(jo==null?"":jo.getString("errInfo")); | ||
266 | + }catch (Exception jError){ | ||
267 | + logger.error("change to json error {} ",result.getBackMsg(),jError); | ||
268 | + } | ||
269 | + }else if(e instanceof HttpServerErrorException){ | ||
270 | + HttpServerErrorException errorException=(HttpServerErrorException)e; | ||
271 | + result.setStatusCode(errorException.getStatusCode().value()); | ||
272 | + result.setBackMsg(errorException.getResponseBodyAsString()); | ||
273 | + try{ | ||
274 | + JSONObject jo=JSONObject.fromObject(errorException.getResponseBodyAsString()); | ||
275 | + result.setErrCode(jo==null?"":jo.getString("errCode")); | ||
276 | + result.setErrInfo(jo==null?"":jo.getString("errInfo")); | ||
277 | + }catch (Exception jError){ | ||
278 | + logger.error("change to json error {} ",result.getBackMsg(),jError); | ||
279 | + } | ||
280 | + }else if(e instanceof RestClientException){ | ||
281 | + RestClientException errorException = (RestClientException)e; | ||
282 | + result.setBackMsg(errorException.getMessage()); | ||
283 | + }else{ | ||
284 | + result.setBackMsg("error happen unknown reason"); | ||
285 | + } | ||
243 | } | 286 | } |
244 | 287 | ||
245 | - return responseEntity; | 288 | + return result; |
289 | + } | ||
290 | + | ||
291 | + @Data | ||
292 | + private static class PostBankResult { | ||
293 | + private boolean sucFlag; | ||
294 | + private int statusCode; | ||
295 | + private String errCode; | ||
296 | + private String errInfo; | ||
297 | + private String backMsg; | ||
246 | } | 298 | } |
247 | 299 | ||
248 | /** | 300 | /** |
249 | * 无论成功还是失败,都把访问记录日志表 | 301 | * 无论成功还是失败,都把访问记录日志表 |
250 | */ | 302 | */ |
251 | - private void recordHistory(int uid,String cardNo,String certNo,String name,int responseCode,String responseContent,long ts){ | 303 | + private void recordHistory(int uid,String cardNo,String certNo,String name,PostBankResult responseResult ,long ts){ |
252 | UserAuthorizeHistory history=new UserAuthorizeHistory(); | 304 | UserAuthorizeHistory history=new UserAuthorizeHistory(); |
253 | history.setUid(uid); | 305 | history.setUid(uid); |
254 | history.setCardNo(cardNo); | 306 | history.setCardNo(cardNo); |
255 | history.setCertNo(certNo); | 307 | history.setCertNo(certNo); |
256 | history.setCertName(name); | 308 | history.setCertName(name); |
257 | - history.setResponseCode(responseCode); | ||
258 | - history.setResponseContent(responseContent); | 309 | + history.setResponseCode(responseResult.getStatusCode()); |
310 | + history.setResponseContent(responseResult.getBackMsg()); | ||
311 | + history.setBackErrorCode(responseResult.getErrCode()); | ||
312 | + history.setBackErrorInfo(responseResult.getErrInfo()); | ||
313 | + history.setFirstErrorCode(EnumBankBackCode.getFirstCodeBySecondCode(responseResult.getErrCode())); | ||
259 | history.setCreateTime(ts); | 314 | history.setCreateTime(ts); |
260 | history.setUpdateTime(ts); | 315 | history.setUpdateTime(ts); |
261 | //最后记录日志 ,异步 | 316 | //最后记录日志 ,异步 |
-
Please register or login to post a comment