cbs8接口
This commit is contained in:
parent
907a5f057f
commit
486ba7b0a8
|
@ -2,7 +2,6 @@ package com.hzya.frame.cbs8.service.impl;
|
|||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hzya.frame.cbs8.dto.req.*;
|
||||
import com.hzya.frame.cbs8.service.ICbs8ExtService;
|
||||
|
@ -13,11 +12,10 @@ import com.hzya.frame.stringutil.StringUtil;
|
|||
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
|
||||
import com.hzya.frame.web.exception.BaseSystemException;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Description
|
||||
|
@ -28,6 +26,7 @@ import java.util.Map;
|
|||
@Service(value = "cbs8Ext")
|
||||
public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(getClass());
|
||||
/**
|
||||
* 支付经办
|
||||
*
|
||||
|
@ -60,7 +59,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
payRequestDTO.setApplyUnitCode(paymentEntity.getPayCompanyCode());
|
||||
payRequestDTO.setPayAccount(null);
|
||||
}
|
||||
String requestData = JSONObject.toJSONString(payRequestDTO);
|
||||
List<PayRequestDTO> list = Arrays.asList(payRequestDTO);
|
||||
String requestData = JSONObject.toJSONString(list);
|
||||
//加密 签名
|
||||
encrypAndsign(entity,requestData);
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
@Override
|
||||
public SysExtensionApiEntity transactionDetailQuery(SysExtensionApiEntity entity) {
|
||||
String bodys = entity.getBodys();
|
||||
if (StrUtil.isEmpty(bodys)){
|
||||
if (StrUtil.isNotEmpty(bodys)){
|
||||
TransactionDetailReqDTO transactionDetailReqDTO = JSONObject.parseObject(bodys,TransactionDetailReqDTO.class);
|
||||
String requestData = JSONObject.toJSONString(transactionDetailReqDTO);
|
||||
////加密签名
|
||||
|
@ -205,11 +205,12 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
private void encrypAndsign(SysExtensionApiEntity entity, String requestData) {
|
||||
//签名
|
||||
long timestamp = System.currentTimeMillis();
|
||||
logger.info("CBS请求参数明文:{}",requestData);
|
||||
String sign = CBSUtil.sign(requestData,timestamp);
|
||||
//加密
|
||||
byte[] encryptedData = CBSUtil.encrypt(requestData);
|
||||
Map<String,String> header = headersValueOf(sign,timestamp);
|
||||
entity.setBodys(Base64.getEncoder().encodeToString(encryptedData));
|
||||
entity.setByteBodys(encryptedData);
|
||||
entity.setHeaders(header);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
|||
import cn.hutool.core.map.MapBuilder;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
|
@ -19,6 +20,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -44,8 +47,16 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterfaceToESB").addHeaders(headerMap).body(JSONObject.toJSONString(paymentEntity)).timeout(60000).execute().body();
|
||||
//解密响应报文
|
||||
String result = decryptResBody(body);
|
||||
PayResponseDTO payResponseDTO = JSONObject.parseObject(result,PayResponseDTO.class);
|
||||
return payResponseDTO;
|
||||
if (StrUtil.isNotEmpty(result)){
|
||||
CbsResponseDTO cbsResponseDTO = JSONObject.parseObject(result, CbsResponseDTO.class);
|
||||
List<JSONObject> dataList = cbsResponseDTO.getData();
|
||||
if (CollectionUtils.isNotEmpty(dataList)){
|
||||
JSONObject o = dataList.get(0);
|
||||
PayResponseDTO payResponseDTO = JSON.toJavaObject(o, PayResponseDTO.class);
|
||||
return payResponseDTO;
|
||||
}
|
||||
}
|
||||
return new PayResponseDTO();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,7 +82,7 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
List<PayResultResDTO> payResultList = CBSUtil.convertJsonArrayToList(dataList, PayResultResDTO.class);
|
||||
return payResultList;
|
||||
}
|
||||
return null;
|
||||
return new ArrayList<PayResultResDTO>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,7 +176,7 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return new CbsResDataDTO();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,7 +207,7 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
return payResponseDTO;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return new PayResponseDTO();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,7 +237,7 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
return agentPayResultResDTO;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return new AgentPayResultResDTO();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -239,8 +250,14 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
JsonResultEntity resultEntity = JSONObject.parseObject(body,JsonResultEntity.class);
|
||||
String bodyBase64 = String.valueOf(resultEntity.getAttribute());
|
||||
byte[] bodyBytes = Base64.getDecoder().decode(bodyBase64);
|
||||
//这里验证一下,如果系统异常 返回的报文没加密
|
||||
String test = new String(bodyBytes);
|
||||
if (JSONUtil.isTypeJSON(test)){
|
||||
return test;
|
||||
}
|
||||
//解密报文
|
||||
String result = CBSUtil.decrypt(bodyBytes);
|
||||
logger.info("银行响应参数:{}",result);
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -227,5 +227,11 @@ public class SM2Util {
|
|||
byte[] decode = Base64.getDecoder().decode(encodeToString);
|
||||
byte[] decrypt1 = decrypt("c3509b6df8bdaf84c464daa1b6fa11a8fca77b0e4a6f076ee68487f288278a85", decode);
|
||||
System.out.println("解密完成1"+new String(decrypt1));
|
||||
|
||||
String base64 = "eyJtc2ciOiLns7vnu5/lvILluLjvvIzor7fnqI3lkI7lho3or5UiLCJkYXRhIjpudWxsLCJjb2RlIjoiNTAwIn0=";
|
||||
byte[] decode1 = Base64.getDecoder().decode(base64);
|
||||
String decode2 = new String(decode1);
|
||||
byte[] decryptbyte = decrypt("83BA7EC821D35F4CB31FF9A51C1EFA520FC52AF828C2337F88E91CF119B07F44", decode1);
|
||||
System.out.println("解密完成"+new String(decryptbyte));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue