|
@@ -11,6 +11,7 @@ import info.aspirecn.iov.sjjh.commons.lang.PatternTools;
|
|
|
import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
|
|
|
import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.jk.SjjhConstant;
|
|
|
import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.jk.service.JKChannelService;
|
|
|
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.jk.utils.SignUtil;
|
|
|
import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.jk.utils.SupplierProperties;
|
|
|
import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.jk.vo.*;
|
|
|
import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.jk_interface.vo.CustomBodyObject;
|
|
@@ -31,9 +32,9 @@ import javax.validation.Validation;
|
|
|
import javax.validation.Validator;
|
|
|
import javax.validation.ValidatorFactory;
|
|
|
import java.net.SocketTimeoutException;
|
|
|
+import java.security.MessageDigest;
|
|
|
import java.util.Set;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* @author jianggang
|
|
@@ -44,20 +45,26 @@ import java.util.regex.Pattern;
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class JKChannelServiceImpl implements JKChannelService {
|
|
|
- @Autowired
|
|
|
+ @Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
- @Value("${custom.url}")
|
|
|
- private String url;
|
|
|
- @Value("${custom.api}")
|
|
|
+ @Value("${custom.url}")
|
|
|
+ private String url;
|
|
|
+ @Value("${custom.api}")
|
|
|
private String api;
|
|
|
- @Value("${custom.appKey}")
|
|
|
+ @Value("${custom.appKey}")
|
|
|
private String appKey;
|
|
|
- @Value("${custom.secretKey}")
|
|
|
+ @Value("${custom.secretKey}")
|
|
|
private String sKey;
|
|
|
- @Value("${custom.mortgage-api}")
|
|
|
- private String mortgageApi;
|
|
|
- @Value("${custom.url-new}")
|
|
|
- private String newUrl;
|
|
|
+ @Value("${custom.url-new}")
|
|
|
+ private String newUrl;
|
|
|
+ @Value("${custom.mortgageUrl}")
|
|
|
+ private String mortgageUrl;
|
|
|
+ @Value("${custom.mortgageApi}")
|
|
|
+ private String mortgageApi;
|
|
|
+ @Value("${custom.mortgageAppKey}")
|
|
|
+ private String mortgageAppKey;
|
|
|
+ @Value("${custom.mortgageAppSecret}")
|
|
|
+ private String mortgageAppSecret;
|
|
|
|
|
|
@Autowired
|
|
|
private SupplierProperties supplierProperties;
|
|
@@ -66,8 +73,9 @@ public class JKChannelServiceImpl implements JKChannelService {
|
|
|
5, TimeUnit.MINUTES);
|
|
|
private OkHttpClient client = new OkHttpClient.Builder().build();
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public ResponseObject sendTwoParamIdCardRequest(String channelId,Integer outTime,String customBody) {
|
|
|
+ public ResponseObject sendTwoParamIdCardRequest(String channelId, Integer outTime, String customBody) {
|
|
|
StopWatch watch = new StopWatch();
|
|
|
watch.start();
|
|
|
TwoParamIdCardResponseObject responseObject = new TwoParamIdCardResponseObject();
|
|
@@ -75,8 +83,8 @@ public class JKChannelServiceImpl implements JKChannelService {
|
|
|
OkHttpClient okHttpClient;
|
|
|
|
|
|
try {
|
|
|
- Preconditions.checkNotNull(channelId,"通道id为空");
|
|
|
- Preconditions.checkNotNull(customBody,"请求json字符串为空");
|
|
|
+ Preconditions.checkNotNull(channelId, "通道id为空");
|
|
|
+ Preconditions.checkNotNull(customBody, "请求json字符串为空");
|
|
|
|
|
|
// //通道id匹配错误
|
|
|
// if (!channelId.equals(Constant.JK_IDCARD_CHANNEL_ID)) {
|
|
@@ -85,354 +93,328 @@ public class JKChannelServiceImpl implements JKChannelService {
|
|
|
// return res;
|
|
|
// }
|
|
|
|
|
|
- /**模拟返回*/
|
|
|
- if(Integer.valueOf(supplierProperties.getSleepTime())==50000){
|
|
|
+ /**模拟返回*/
|
|
|
+ if (Integer.valueOf(supplierProperties.getSleepTime()) == 50000) {
|
|
|
res.setIsCharge(Constant.INTERFACE_QUERY_FEE);
|
|
|
res.setCode(Constant.SUCCESS);
|
|
|
TwoParamIdCardResponseObject twoParamIdCardResponseObject = new TwoParamIdCardResponseObject();
|
|
|
twoParamIdCardResponseObject.setCode(200);
|
|
|
twoParamIdCardResponseObject.setResult("101");
|
|
|
res.setResultBody(twoParamIdCardResponseObject);
|
|
|
- return res;
|
|
|
- }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
|
|
|
- /**模拟错误*/
|
|
|
- if(Integer.valueOf(supplierProperties.getSleepTime())==20000){
|
|
|
- throw new IllegalArgumentException();
|
|
|
- }
|
|
|
+ /**模拟错误*/
|
|
|
+ if (Integer.valueOf(supplierProperties.getSleepTime()) == 20000) {
|
|
|
+ throw new IllegalArgumentException();
|
|
|
+ }
|
|
|
|
|
|
/**模拟超时*/
|
|
|
- if(outTime < Integer.valueOf(supplierProperties.getSleepTime())){
|
|
|
- log.error("simulation SocketTimeoutException--->outTime:{}--->sleepTime:{}",outTime,supplierProperties.getSleepTime());
|
|
|
+ if (outTime < Integer.valueOf(supplierProperties.getSleepTime())) {
|
|
|
+ log.error("simulation SocketTimeoutException--->outTime:{}--->sleepTime:{}", outTime, supplierProperties.getSleepTime());
|
|
|
throw new SocketTimeoutException();
|
|
|
}
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
- CustomBodyObject customBodyObject = mapper.readValue(customBody,CustomBodyObject.class);
|
|
|
- Preconditions.checkNotNull(customBodyObject.getName(),"姓名不能为空");
|
|
|
- Preconditions.checkNotNull(customBodyObject.getIdCode(),"身份证不能为空");
|
|
|
+ CustomBodyObject customBodyObject = mapper.readValue(customBody, CustomBodyObject.class);
|
|
|
+ Preconditions.checkNotNull(customBodyObject.getName(), "姓名不能为空");
|
|
|
+ Preconditions.checkNotNull(customBodyObject.getIdCode(), "身份证不能为空");
|
|
|
|
|
|
- if(outTime == null && outTime <= 0){
|
|
|
+ if (outTime == null && outTime <= 0) {
|
|
|
outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
}
|
|
|
|
|
|
okHttpClient = client.newBuilder()
|
|
|
- .connectTimeout(outTime,TimeUnit.MILLISECONDS)
|
|
|
- .writeTimeout(outTime,TimeUnit.MILLISECONDS)
|
|
|
- .readTimeout(outTime,TimeUnit.MILLISECONDS)
|
|
|
+ .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
.connectionPool(POOL)
|
|
|
.build();
|
|
|
res.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
res.setCode(Constant.FAIL);
|
|
|
- String url = supplierProperties.getUrl()+"?cname="+customBodyObject.getName()+"&cid="+customBodyObject.getIdCode();
|
|
|
+ String url = supplierProperties.getUrl() + "?cname=" + customBodyObject.getName() + "&cid=" + customBodyObject.getIdCode();
|
|
|
Request request = new Request.Builder()
|
|
|
.url(url)
|
|
|
.build();
|
|
|
StopWatch watch1 = new StopWatch();
|
|
|
watch1.start();
|
|
|
Response response = okHttpClient.newCall(request).execute();
|
|
|
- String responseJson = response.body().string();
|
|
|
- log.info("---->上游返回结果{}",responseJson);
|
|
|
+ String responseJson = response.body().string();
|
|
|
+ log.info("---->上游返回结果{}", responseJson);
|
|
|
watch1.stop();
|
|
|
- log.info("upStream request time : {}",watch1.getTotalTimeSeconds());
|
|
|
- if(response.code()==200){
|
|
|
- res.setCode(Constant.SUCCESS);
|
|
|
- responseObject = mapper.readValue(responseJson, TwoParamIdCardResponseObject.class);
|
|
|
- res.setResultBody(responseObject);
|
|
|
- //判断是否计费
|
|
|
- if (responseObject.getCode() == 200) {
|
|
|
- res.setIsCharge(Constant.INTERFACE_QUERY_FEE);
|
|
|
- }
|
|
|
+ log.info("upStream request time : {}", watch1.getTotalTimeSeconds());
|
|
|
+ if (response.code() == 200) {
|
|
|
+ res.setCode(Constant.SUCCESS);
|
|
|
+ responseObject = mapper.readValue(responseJson, TwoParamIdCardResponseObject.class);
|
|
|
+ res.setResultBody(responseObject);
|
|
|
+ //判断是否计费
|
|
|
+ if (responseObject.getCode() == 200) {
|
|
|
+ res.setIsCharge(Constant.INTERFACE_QUERY_FEE);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- }catch (SocketTimeoutException e) {
|
|
|
- log.error("SocketTimeoutException message:{}",e);
|
|
|
+ } catch (SocketTimeoutException e) {
|
|
|
+ log.error("SocketTimeoutException message:{}", e);
|
|
|
ErrorUtils.captureException(e);
|
|
|
res.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
res.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
return res;
|
|
|
- }catch (Exception e){
|
|
|
- log.error("Exception message:{}",e);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Exception message:{}", e);
|
|
|
ErrorUtils.captureException(e);
|
|
|
res.setCode(Constant.FAIL);
|
|
|
res.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
return res;
|
|
|
}
|
|
|
watch.stop();
|
|
|
- log.info("service request time : {}",watch.getTotalTimeSeconds());
|
|
|
+ log.info("service request time : {}", watch.getTotalTimeSeconds());
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public EncryptionResponseObject encryptionMobileCheck(String customBody, int outTime) {
|
|
|
+ EncryptionResponseObject ret = new EncryptionResponseObject();
|
|
|
+ try {
|
|
|
+ if (outTime <= 0) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("encryptionMobileCheck---customBody={},outTime={}", customBody, outTime);
|
|
|
+ JsonResolveObject jsonResolveObject = objectMapper.readValue(customBody,
|
|
|
+ JsonResolveObject.class);
|
|
|
+
|
|
|
+
|
|
|
+ log.info("encryptionMobileCheck---requestObject={}", jsonResolveObject);
|
|
|
+ String name = jsonResolveObject.getName();
|
|
|
+ String idCode = jsonResolveObject.getIdCode();
|
|
|
+ String mobile = jsonResolveObject.getMobile();
|
|
|
+
|
|
|
+ EncryptionMobileCheckRequestObject requestObject = new EncryptionMobileCheckRequestObject();
|
|
|
+ requestObject.setApi(api);
|
|
|
+ requestObject.setAppKey(appKey);
|
|
|
+ requestObject.setAppSecret(sKey);
|
|
|
+
|
|
|
+ EncryptionMobileCheckRequestChildObject requestChildObject = new EncryptionMobileCheckRequestChildObject();
|
|
|
+ requestChildObject.setEncrypt(SjjhConstant.ENCRYPTION_SHA256);
|
|
|
+ requestChildObject.setId_number(idCode);
|
|
|
+ requestChildObject.setMobile(mobile);
|
|
|
+ requestChildObject.setName(name);
|
|
|
+ String sign = Md5Util.encrypt32("appSecret=" + sKey + "&enctype=" + SjjhConstant.ENCRYPTION_SHA256
|
|
|
+ + "&id_number=" + idCode + "&mobile=" + mobile + "&name=" + name);
|
|
|
+ requestChildObject.setSign(sign);
|
|
|
+ requestObject.setData(objectMapper.writeValueAsString(requestChildObject));
|
|
|
+ String jsonStr = objectMapper.writeValueAsString(requestObject);
|
|
|
+ log.info("调用三要素加密接口时传的JSON:" + jsonStr);
|
|
|
+ MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
|
|
|
+ RequestBody requestBody = RequestBody.create(mediaType, jsonStr);
|
|
|
+
|
|
|
+ Request request = new Request.Builder().post(requestBody).url(url).build();
|
|
|
+ OkHttpClient httpClient = client.newBuilder()
|
|
|
+ .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .build();
|
|
|
+ Response response = httpClient.newCall(request).execute();
|
|
|
+ String responseContext = response.body().string();
|
|
|
+ log.info("三要素加密版responseContext={}", responseContext);
|
|
|
+
|
|
|
+ EncryptionMobileCheckResponseObject responseObject = objectMapper.readValue(responseContext,
|
|
|
+ EncryptionMobileCheckResponseObject.class);
|
|
|
+
|
|
|
+
|
|
|
+ //返回结果中的code为200时,data为1或0时收费
|
|
|
+ if (responseObject != null) {
|
|
|
+ boolean bool = SjjhConstant.RETURN_SUCCESS.equals(responseObject.getCode())
|
|
|
+ && (SjjhConstant.QUERY_IDENTICAL.equalsIgnoreCase(responseObject.getData())
|
|
|
+ || SjjhConstant.QUERY_NO_IDENTICAL.equalsIgnoreCase(responseObject.getData()));
|
|
|
+ if (bool) {
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_FEE);
|
|
|
+ }
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ ret.setMessage("查询成功");
|
|
|
+ ret.setResultBody(responseObject);
|
|
|
+ response.close();
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ ret.setMessage("接口调用超时");
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ } catch (Exception ioe) {
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ ret.setMessage("接口调用失败");
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public EncryptionResponseObject encryptionMobileCheck(String customBody,int outTime){
|
|
|
- EncryptionResponseObject ret = new EncryptionResponseObject();
|
|
|
- try {
|
|
|
- if(outTime <= 0) {
|
|
|
- outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
- }
|
|
|
-
|
|
|
- log.info("encryptionMobileCheck---customBody={},outTime={}",customBody,outTime);
|
|
|
- JsonResolveObject jsonResolveObject = objectMapper.readValue(customBody,
|
|
|
- JsonResolveObject.class);
|
|
|
-
|
|
|
-
|
|
|
- log.info("encryptionMobileCheck---requestObject={}",jsonResolveObject);
|
|
|
- String name = jsonResolveObject.getName();
|
|
|
- String idCode = jsonResolveObject.getIdCode();
|
|
|
- String mobile = jsonResolveObject.getMobile();
|
|
|
-
|
|
|
- EncryptionMobileCheckRequestObject requestObject = new EncryptionMobileCheckRequestObject();
|
|
|
- requestObject.setApi(api);
|
|
|
- requestObject.setAppKey(appKey);
|
|
|
- requestObject.setAppSecret(sKey);
|
|
|
-
|
|
|
- EncryptionMobileCheckRequestChildObject requestChildObject = new EncryptionMobileCheckRequestChildObject();
|
|
|
- requestChildObject.setEncrypt(SjjhConstant.ENCRYPTION_SHA256);
|
|
|
- requestChildObject.setId_number(idCode);
|
|
|
- requestChildObject.setMobile(mobile);
|
|
|
- requestChildObject.setName(name);
|
|
|
- String sign = Md5Util.encrypt32("appSecret="+ sKey +"&enctype=" + SjjhConstant.ENCRYPTION_SHA256
|
|
|
- +"&id_number="+ idCode +"&mobile="+ mobile +"&name="+ name);
|
|
|
- requestChildObject.setSign(sign);
|
|
|
- requestObject.setData(objectMapper.writeValueAsString(requestChildObject));
|
|
|
- String jsonStr = objectMapper.writeValueAsString(requestObject);
|
|
|
- log.info("调用三要素加密接口时传的JSON:"+jsonStr);
|
|
|
- MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
|
|
|
- RequestBody requestBody = RequestBody.create(mediaType, jsonStr);
|
|
|
-
|
|
|
- Request request = new Request.Builder().post(requestBody).url(url).build();
|
|
|
- OkHttpClient httpClient = client.newBuilder()
|
|
|
- .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
- .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
- .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
- .build();
|
|
|
- Response response = httpClient.newCall(request).execute();
|
|
|
- String responseContext = response.body().string();
|
|
|
- log.info("三要素加密版responseContext={}",responseContext);
|
|
|
-
|
|
|
- EncryptionMobileCheckResponseObject responseObject = objectMapper.readValue(responseContext,
|
|
|
- EncryptionMobileCheckResponseObject.class);
|
|
|
-
|
|
|
-
|
|
|
- //返回结果中的code为200时,data为1或0时收费
|
|
|
- if(responseObject != null) {
|
|
|
- boolean bool = SjjhConstant.RETURN_SUCCESS.equals(responseObject.getCode())
|
|
|
- && (SjjhConstant.QUERY_IDENTICAL.equalsIgnoreCase(responseObject.getData())
|
|
|
- || SjjhConstant.QUERY_NO_IDENTICAL.equalsIgnoreCase(responseObject.getData()));
|
|
|
- if(bool) {
|
|
|
- ret.setIsCharge(Constant.INTERFACE_QUERY_FEE);
|
|
|
- }
|
|
|
- ret.setCode(Constant.SUCCESS);
|
|
|
- ret.setMessage("查询成功");
|
|
|
- ret.setResultBody(responseObject);
|
|
|
- response.close();
|
|
|
- } else {
|
|
|
- ret.setCode(Constant.FAIL);
|
|
|
- ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
- }
|
|
|
-
|
|
|
- } catch(SocketTimeoutException ste) {
|
|
|
- ErrorUtils.captureException(ste);
|
|
|
- ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
- ret.setMessage("接口调用超时");
|
|
|
- ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
- } catch(Exception ioe) {
|
|
|
- ErrorUtils.captureException(ioe);
|
|
|
- ret.setCode(Constant.FAIL);
|
|
|
- ret.setMessage("接口调用失败");
|
|
|
- ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
- }
|
|
|
-
|
|
|
- return ret;
|
|
|
+ public ChannelTypeHandleResponseObject vehicleMortgage(HttpServletRequest request, String customBody, int outTime) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
+ String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(returnType)) {
|
|
|
+ returnType = Constant.CUSTOMER_RETURN_ZW;
|
|
|
+ }
|
|
|
+ if (outTime <= 0) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("vehicleMortgage---customBody={},outTime={}", customBody, outTime);
|
|
|
+
|
|
|
+ try {
|
|
|
+ VehicleMortgageJsonResolveObject jsonResolveObject = objectMapper.readValue(customBody, VehicleMortgageJsonResolveObject.class);
|
|
|
+ //参数校验
|
|
|
+ if (!validateVehicleMortgageParams(ret, returnType, jsonResolveObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("vehicleNo", jsonResolveObject.getPlateNumber());
|
|
|
+ jsonObject.put("vin", "");
|
|
|
+ jsonObject.put("engineNumber", "");
|
|
|
+ jsonObject.put("vehicleIdentificationNumber", "");
|
|
|
+ String sign = SignUtil.getSign(mortgageAppSecret, SignUtil.getSignData(jsonObject));
|
|
|
+ jsonObject.put("sign", sign);
|
|
|
+ VehicleMortgageRequestObject requestObject = new VehicleMortgageRequestObject();
|
|
|
+ requestObject.setApi(mortgageApi);
|
|
|
+ requestObject.setAppKey(mortgageAppKey);
|
|
|
+ requestObject.setData(jsonObject);
|
|
|
+
|
|
|
+ MediaType mediaType = MediaType.parse(SjjhConstant.MEDIA_TYPE);
|
|
|
+ RequestBody requestBody = RequestBody.create(mediaType, JSON.toJSONString(requestObject));
|
|
|
+ Request okRequest = new Request.Builder()
|
|
|
+ .post(requestBody)
|
|
|
+ .url(mortgageUrl)
|
|
|
+ .build();
|
|
|
+ OkHttpClient client = new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .build();
|
|
|
+ Response response = client.newCall(okRequest).execute();
|
|
|
+ String responseContext = "";
|
|
|
+ if (response.body() != null) {
|
|
|
+ responseContext = response.body().string();
|
|
|
+ }
|
|
|
+ log.info("supplier10000001.vehicleMortgage接口responseContext={}", responseContext);
|
|
|
+ JKResponseObject responseObject = JSON.toJavaObject(JSON.parseObject(responseContext), JKResponseObject.class);
|
|
|
+ log.info("supplier10000001.vehicleMortgage接口responseObject={}", responseObject);
|
|
|
+ if (responseObject != null) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ setVehicleMortgageResponse(ret, responseObject);
|
|
|
+ upstreamCode = String.valueOf(responseObject.getCode());
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ response.close();
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
+ log.info("supplier10000001.vehicleMortgage接口SocketTimeoutException=", ste);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ } catch (Exception ioe) {
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ log.info("supplier10000001.vehicleMortgage接口Exception=", ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ //上游返回码
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setVehicleMortgageResponse(ChannelTypeHandleResponseObject ret, JKResponseObject responseObject) {
|
|
|
+ if (responseObject != null
|
|
|
+ && responseObject.getCode().equals(SjjhConstant.RETURN_SUCCESS)
|
|
|
+ && responseObject.getData().equals(SjjhConstant.RESPONSE_DATA_1)) {
|
|
|
+ JSONObject msgObject = JSONObject.parseObject(responseObject.getMsg());
|
|
|
+ String mortgageFlag = String.valueOf(msgObject.get("DYBJ"));
|
|
|
+ // 未抵押
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_MATCH);
|
|
|
+ ret.setResultBody(mortgageFlag);
|
|
|
+ ret.setResultDesc(mortgageFlag);
|
|
|
+ ret.setIsCharge(Constant.IS_CHARGE);
|
|
|
+ } else if (responseObject != null
|
|
|
+ && responseObject.getCode().equals(SjjhConstant.RETURN_SUCCESS)
|
|
|
+ && responseObject.getData().equals(SjjhConstant.RESPONSE_DATA_2)) {
|
|
|
+ // 库无
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_NO_INFO);
|
|
|
+ ret.setResultBody(SjjhConstant.UN_FIND_MESSAGE);
|
|
|
+ ret.setResultDesc(SjjhConstant.UN_FIND_MESSAGE);
|
|
|
+ } else {
|
|
|
+ // 查询错误
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateVehicleMortgageParams(ChannelTypeHandleResponseObject ret, String returnType, VehicleMortgageJsonResolveObject jsonResolveObject) {
|
|
|
+ if (!validateParamNullValue(jsonResolveObject)) {
|
|
|
+ // 参数名错误
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ }
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ return false;
|
|
|
+ } else if (StringUtils.isBlank(jsonResolveObject.getPlateNumber())
|
|
|
+ || !PatternTools.checkResult(Constant.PATTERN_CAR_NUMBER_REGEX, jsonResolveObject.getPlateNumber())) {
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ }
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public ChannelTypeHandleResponseObject vehicleMortgage(HttpServletRequest request, String customBody, int outTime) {
|
|
|
- ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
- ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
- String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
- String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
|
|
|
-
|
|
|
- if (StringUtils.isBlank(returnType)) {
|
|
|
- returnType = Constant.CUSTOMER_RETURN_ZW;
|
|
|
- }
|
|
|
- if (outTime <= 0) {
|
|
|
- outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
- }
|
|
|
- log.info("vehicleMortgage---customBody={},outTime={}", customBody, outTime);
|
|
|
-
|
|
|
- try {
|
|
|
- VehicleMortgageJsonResolveObject jsonResolveObject = objectMapper.readValue(customBody, VehicleMortgageJsonResolveObject.class);
|
|
|
- //参数校验
|
|
|
- if (!validateVehicleMortgageParams(ret, returnType, jsonResolveObject)) {
|
|
|
- ret.setCode(Constant.SUCCESS);
|
|
|
- request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(jsonResolveObject));
|
|
|
- jsonObject.put("vehicleIdentificationNumber", jsonResolveObject.getVin().substring(jsonResolveObject.getVin().length()-6));
|
|
|
- VehicleMortgageRequestObject requestObject = new VehicleMortgageRequestObject();
|
|
|
- requestObject.setApi(mortgageApi);
|
|
|
- requestObject.setAppKey(appKey);
|
|
|
- requestObject.setAppSecret(sKey);
|
|
|
- requestObject.setData(jsonObject.toJSONString());
|
|
|
-
|
|
|
- MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
|
|
|
- RequestBody requestBody = RequestBody.create(mediaType, JSON.toJSONString(requestObject));
|
|
|
- Request okRequest = new Request.Builder()
|
|
|
- .post(requestBody)
|
|
|
- .url(newUrl)
|
|
|
- .build();
|
|
|
- OkHttpClient client = new OkHttpClient.Builder()
|
|
|
- .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
- .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
- .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
- .build();
|
|
|
- Response response = client.newCall(okRequest).execute();
|
|
|
- String responseContext = "";
|
|
|
- if (response.body() != null) {
|
|
|
- responseContext = response.body().string();
|
|
|
- }
|
|
|
- log.info("supplier10000001.vehicleMortgage接口responseContext={}", responseContext);
|
|
|
- JKResponseObject responseObject = objectMapper.readValue(responseContext, JKResponseObject.class);
|
|
|
- log.info("supplier10000001.vehicleMortgage接口responseObject={}", responseObject);
|
|
|
- if (responseObject != null) {
|
|
|
- ret.setCode(Constant.SUCCESS);
|
|
|
- setVehicleMortgageResponse(ret, returnType, responseObject);
|
|
|
- upstreamCode = String.valueOf(responseObject.getCode());
|
|
|
- response.close();
|
|
|
- } else {
|
|
|
- ret.setCode(Constant.FAIL);
|
|
|
- }
|
|
|
- } catch (SocketTimeoutException ste) {
|
|
|
- ErrorUtils.captureException(ste);
|
|
|
- log.info("supplier10000001.vehicleMortgage接口SocketTimeoutException={}", ste);
|
|
|
- ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
- } catch (Exception ioe) {
|
|
|
- ErrorUtils.captureException(ioe);
|
|
|
- log.info("supplier10000001.vehicleMortgage接口Exception={}", ioe);
|
|
|
- ret.setCode(Constant.FAIL);
|
|
|
- }
|
|
|
-
|
|
|
- //上游返回码
|
|
|
- request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
- return ret;
|
|
|
- }
|
|
|
- private void setVehicleMortgageResponse(ChannelTypeHandleResponseObject ret, String returnType, JKResponseObject responseObject) {
|
|
|
- boolean isCharge = responseObject != null
|
|
|
- && (responseObject.getCode().equals(SjjhConstant.RETURN_SUCCESS)
|
|
|
- && (responseObject.getData().equals(SjjhConstant.RESPONSE_DATA_1)
|
|
|
- || responseObject.getData().equals(SjjhConstant.RESPONSE_DATA_2)));
|
|
|
- if (isCharge) {
|
|
|
- ret.setIsCharge(Constant.INTERFACE_QUERY_FEE);
|
|
|
- }
|
|
|
-
|
|
|
- if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
|
|
|
- if (responseObject.getCode().equals(SjjhConstant.RETURN_SUCCESS) && responseObject.getData().equals(SjjhConstant.RESPONSE_DATA_1)) {
|
|
|
- JSONObject msgObject = JSONObject.parseObject(responseObject.getMsg());
|
|
|
- String mortgageFlag = String.valueOf(msgObject.get("DYBJ"));
|
|
|
- if (mortgageFlag.equals(SjjhConstant.RESPONSE_DYBJ_0)) {
|
|
|
- // 未抵押
|
|
|
- ret.setResultCode(Constant.JK_RETURN_CODE_1171);
|
|
|
- ret.setResultBody(Constant.RETURN_MESSAGE_111);
|
|
|
- ret.setResultDesc(Constant.RETURN_MESSAGE_111);
|
|
|
- } else if (mortgageFlag.equals(SjjhConstant.RESPONSE_DYBJ_1)) {
|
|
|
- // 抵押
|
|
|
- ret.setResultCode(Constant.JK_RETURN_CODE_1172);
|
|
|
- ret.setResultBody(Constant.RETURN_MESSAGE_112);
|
|
|
- ret.setResultDesc(Constant.RETURN_MESSAGE_112);
|
|
|
- } else {
|
|
|
- // 质押
|
|
|
- ret.setResultCode(Constant.JK_RETURN_CODE_1173);
|
|
|
- ret.setResultBody(Constant.RETURN_MESSAGE_113);
|
|
|
- ret.setResultDesc(Constant.RETURN_MESSAGE_113);
|
|
|
- }
|
|
|
- } else if (responseObject.getCode().equals(SjjhConstant.RETURN_SUCCESS) && responseObject.getData().equals(SjjhConstant.RESPONSE_DATA_2)) {
|
|
|
- // 库无
|
|
|
- ret.setResultCode(Constant.JK_RETURN_CODE_NO_INFO);
|
|
|
- ret.setResultBody(Constant.UN_FIND_NUM);
|
|
|
- ret.setResultDesc(Constant.UN_FIND_NUM);
|
|
|
- } else {
|
|
|
- // 查询错误
|
|
|
- ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
|
|
|
- ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
- ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (responseObject.getCode().equals(SjjhConstant.RETURN_SUCCESS) && responseObject.getData().equals(SjjhConstant.RESPONSE_DATA_1)) {
|
|
|
- JSONObject msgObject = JSONObject.parseObject(responseObject.getMsg());
|
|
|
- String mortgageFlag = String.valueOf(msgObject.get("DYBJ"));
|
|
|
- if (mortgageFlag.equals(SjjhConstant.RESPONSE_DYBJ_0)) {
|
|
|
- // 未抵押
|
|
|
- ret.setResultCode(Constant.ZW_RETURN_CODE_111);
|
|
|
- ret.setResultBody(Constant.RETURN_MESSAGE_111);
|
|
|
- ret.setResultDesc(Constant.RETURN_MESSAGE_111);
|
|
|
- } else if (mortgageFlag.equals(SjjhConstant.RESPONSE_DYBJ_1)) {
|
|
|
- // 抵押
|
|
|
- ret.setResultCode(Constant.ZW_RETURN_CODE_112);
|
|
|
- ret.setResultBody(Constant.RETURN_MESSAGE_112);
|
|
|
- ret.setResultDesc(Constant.RETURN_MESSAGE_112);
|
|
|
- } else {
|
|
|
- // 质押
|
|
|
- ret.setResultCode(Constant.ZW_RETURN_CODE_113);
|
|
|
- ret.setResultBody(Constant.RETURN_MESSAGE_113);
|
|
|
- ret.setResultDesc(Constant.RETURN_MESSAGE_113);
|
|
|
- }
|
|
|
- } else if (responseObject.getCode().equals(SjjhConstant.RETURN_SUCCESS) && responseObject.getData().equals(SjjhConstant.RESPONSE_DATA_2)) {
|
|
|
- // 库无
|
|
|
- ret.setResultCode(Constant.UN_FIND_NUM_CODE);
|
|
|
- ret.setResultBody(Constant.UN_FIND_NUM);
|
|
|
- ret.setResultDesc(Constant.UN_FIND_NUM);
|
|
|
- } else {
|
|
|
- // 查询错误
|
|
|
- ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
- ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
- ret.setResultDesc(Constant.OTHER_ERROR);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private boolean validateVehicleMortgageParams(ChannelTypeHandleResponseObject ret, String returnType, VehicleMortgageJsonResolveObject jsonResolveObject) {
|
|
|
- if (!validateParamNullValue(jsonResolveObject)) {
|
|
|
- // 参数名错误
|
|
|
- if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
- ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
- } else {
|
|
|
- ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
- }
|
|
|
- ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
- ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
- return false;
|
|
|
- } else if (StringUtils.isBlank(jsonResolveObject.getPlateNumber())
|
|
|
- || StringUtils.isBlank(jsonResolveObject.getEngineNumber())
|
|
|
- || StringUtils.isBlank(jsonResolveObject.getVin())
|
|
|
- || !PatternTools.checkResult(Constant.PATTERN_CAR_NUMBER_REGEX, jsonResolveObject.getPlateNumber())
|
|
|
- || !Pattern.compile("[a-zA-Z0-9]{17}").matcher(jsonResolveObject.getVin()).matches()
|
|
|
- || !Pattern.compile("^[A-Za-z0-9]+$").matcher(jsonResolveObject.getEngineNumber()).matches()) {
|
|
|
- if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
- ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
- } else {
|
|
|
- ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
- }
|
|
|
- ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
- ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- private boolean validateParamNullValue(Object jsonResolveObject) {
|
|
|
- ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
|
|
- Validator validator = vf.getValidator();
|
|
|
- Set<ConstraintViolation<Object>> set = validator.validate(jsonResolveObject);
|
|
|
- for (ConstraintViolation<Object> con : set) {
|
|
|
- if (StringUtils.isNotBlank(con.getMessage())) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
+ private boolean validateParamNullValue(Object jsonResolveObject) {
|
|
|
+ ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
|
|
|
+ Validator validator = vf.getValidator();
|
|
|
+ Set<ConstraintViolation<Object>> set = validator.validate(jsonResolveObject);
|
|
|
+ for (ConstraintViolation<Object> con : set) {
|
|
|
+ if (StringUtils.isNotBlank(con.getMessage())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getSign(String signKey, String content) {
|
|
|
+ String result = content + "&" + signKey;
|
|
|
+ try {
|
|
|
+ MessageDigest md5 = MessageDigest.getInstance("MD5");
|
|
|
+ byte[] byteArray = result.getBytes("UTF-8");
|
|
|
+ byte[] md5Bytes = md5.digest(byteArray);
|
|
|
+ StringBuffer hexValue = new StringBuffer();
|
|
|
+ for (int i = 0; i < md5Bytes.length; i++) {
|
|
|
+ int val = ((int) md5Bytes[i]) & 0xff;
|
|
|
+ if (val < 16) {
|
|
|
+ hexValue.append("0");
|
|
|
+ }
|
|
|
+ hexValue.append(Integer.toHexString(val));
|
|
|
+ }
|
|
|
+ return hexValue.toString().toUpperCase();
|
|
|
+ } catch (Exception e) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|