保存日志

This commit is contained in:
xiang2lin 2024-07-04 10:19:51 +08:00
parent 9fd9436d94
commit 25696996d7
3 changed files with 123 additions and 67 deletions

View File

@ -1,5 +1,12 @@
package com.hzya.frame.cbs8.dto.res; package com.hzya.frame.cbs8.dto.res;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import java.util.List;
/** /**
* @Description 经办支付接口返回参数中的data节点 * @Description 经办支付接口返回参数中的data节点
* @Author xiangerlin * @Author xiangerlin
@ -70,4 +77,22 @@ public class PayResponseDTO {
public void setSuccessed(Boolean successed) { public void setSuccessed(Boolean successed) {
this.successed = successed; this.successed = successed;
} }
/**
* 从银行响应报文解析
* @param result
* @return
*/
public static PayResponseDTO payResValueOf(String result){
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();
}
} }

View File

@ -4,6 +4,7 @@ import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hzya.frame.cbs8.dto.req.*; import com.hzya.frame.cbs8.dto.req.*;
import com.hzya.frame.cbs8.dto.res.PayResponseDTO;
import com.hzya.frame.cbs8.service.ICbs8ExtService; import com.hzya.frame.cbs8.service.ICbs8ExtService;
import com.hzya.frame.cbs8.util.CBSUtil; import com.hzya.frame.cbs8.util.CBSUtil;
import com.hzya.frame.cbs8.util.CbsAccessToken; import com.hzya.frame.cbs8.util.CbsAccessToken;
@ -11,12 +12,14 @@ import com.hzya.frame.seeyon.cbs8.entity.PaymentEntity;
import com.hzya.frame.stringutil.StringUtil; import com.hzya.frame.stringutil.StringUtil;
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity; import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
import com.hzya.frame.sysnew.integtationTaskLivingDetails.entity.IntegrationTaskLivingDetailsEntity; import com.hzya.frame.sysnew.integtationTaskLivingDetails.entity.IntegrationTaskLivingDetailsEntity;
import com.hzya.frame.sysnew.integtationTaskLivingDetails.service.IIntegrationTaskLivingDetailsService;
import com.hzya.frame.sysnew.messageManageLog.entity.SysMessageManageLogEntity; import com.hzya.frame.sysnew.messageManageLog.entity.SysMessageManageLogEntity;
import com.hzya.frame.web.exception.BaseSystemException; import com.hzya.frame.web.exception.BaseSystemException;
import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HTTP;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
/** /**
@ -29,6 +32,8 @@ import java.util.*;
public class Cbs8ExtServiceImpl implements ICbs8ExtService { public class Cbs8ExtServiceImpl implements ICbs8ExtService {
Logger logger = LoggerFactory.getLogger(getClass()); Logger logger = LoggerFactory.getLogger(getClass());
private IIntegrationTaskLivingDetailsService taskLivingDetailsService;
/** /**
* 支付经办 * 支付经办
* *
@ -38,11 +43,11 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
@Override @Override
public SysExtensionApiEntity payApply(SysExtensionApiEntity entity) { public SysExtensionApiEntity payApply(SysExtensionApiEntity entity) {
String bodys = entity.getBodys(); String bodys = entity.getBodys();
if (StrUtil.isNotEmpty(bodys)){ if (StrUtil.isNotEmpty(bodys)) {
PaymentEntity paymentEntity = JSONObject.parseObject(bodys,PaymentEntity.class); PaymentEntity paymentEntity = JSONObject.parseObject(bodys, PaymentEntity.class);
if (null != paymentEntity){ if (null != paymentEntity) {
PayRequestDTO payRequestDTO = new PayRequestDTO(); PayRequestDTO payRequestDTO = new PayRequestDTO();
String ferenceNum = Convert.toStr(paymentEntity.getReferenceNumNew(),paymentEntity.getReferenceNum()); String ferenceNum = Convert.toStr(paymentEntity.getReferenceNumNew(), paymentEntity.getReferenceNum());
payRequestDTO.setReferenceNum(ferenceNum); payRequestDTO.setReferenceNum(ferenceNum);
payRequestDTO.setBusType(paymentEntity.getBusType()); payRequestDTO.setBusType(paymentEntity.getBusType());
payRequestDTO.setAmount(paymentEntity.getAmount()); payRequestDTO.setAmount(paymentEntity.getAmount());
@ -56,7 +61,7 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
payRequestDTO.setPurpose(paymentEntity.getPurpose()); payRequestDTO.setPurpose(paymentEntity.getPurpose());
payRequestDTO.setErpExtend1(paymentEntity.getPayType()); payRequestDTO.setErpExtend1(paymentEntity.getPayType());
//集中支付模式 //集中支付模式
if (CBSUtil.CENTRALIZED_PAYMENT_TYPE.equals(payRequestDTO.getBusType())){ if (CBSUtil.CENTRALIZED_PAYMENT_TYPE.equals(payRequestDTO.getBusType())) {
payRequestDTO.setBusiStep("1"); payRequestDTO.setBusiStep("1");
payRequestDTO.setApplyUnitCode(paymentEntity.getPayCompanyCode()); payRequestDTO.setApplyUnitCode(paymentEntity.getPayCompanyCode());
payRequestDTO.setPayAccount(null); payRequestDTO.setPayAccount(null);
@ -64,8 +69,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
List<PayRequestDTO> list = Arrays.asList(payRequestDTO); List<PayRequestDTO> list = Arrays.asList(payRequestDTO);
String requestData = JSONObject.toJSONString(list); String requestData = JSONObject.toJSONString(list);
//加密 签名 //加密 签名
encrypAndsign(entity,requestData); encrypAndsign(entity, requestData);
entity.setBodys(JSONObject.toJSONString(payRequestDTO)); entity.setBodys(requestData);
} }
} }
return entity; return entity;
@ -78,18 +83,40 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
*/ */
@Override @Override
public void payApplyCallBack(SysMessageManageLogEntity logEntity) { public void payApplyCallBack(SysMessageManageLogEntity logEntity) {
try {
//todo 这里要验证一下bodys里有没有数据 //todo 这里要验证一下bodys里有没有数据
logger.info("回调方法里的参数:{}",JSONObject.toJSONString(logEntity)); logger.info("回调方法里的参数:{}", JSONObject.toJSONString(logEntity));
JSONObject targetData = JSONObject.parseObject(logEntity.getTargetData());//目标数据
JSONObject sourceData = JSONObject.parseObject(logEntity.getSourceData());//源数据
JSONObject sourceHeaders = sourceData.getJSONObject("header");//源header
JSONObject targetHeaders = targetData.getJSONObject("header");//目标header
JSONObject sourceBody = sourceData.getJSONObject("body");//源数据body
//自定义参数存放的是请求报文明文
String hzyaExtData = targetHeaders.getString("hzyaExtData");
String returnDataBase64 = logEntity.getReturnData();
byte[] secretResByte = Base64.getDecoder().decode(returnDataBase64);
//解密报文
String decryptRes = CBSUtil.decrypt(secretResByte);
//6记录系统日志 //6记录系统日志
IntegrationTaskLivingDetailsEntity logTask = new IntegrationTaskLivingDetailsEntity(); IntegrationTaskLivingDetailsEntity logTask = new IntegrationTaskLivingDetailsEntity();
//logTask.setRootAppPk(pay.getFormsonId()); logTask.setRootAppPk(sourceBody.getString("formsonId"));
//logTask.setRootAppBill(pay.getReferenceNum()); logTask.setRootAppBill(sourceBody.getString("referenceNum"));
logTask.setPluginId("CBS8PayApplyPlugin");
//对方接口返回信息 //对方接口返回信息
//logTask.setNewTransmitInfo(JSONObject.toJSONString(payResponseDTO)); logTask.setNewTransmitInfo(decryptRes);
logTask.setNewPushDate(new Date()); logTask.setNewPushDate(new Date());
//调用接口请求参数 //调用接口请求参数
logTask.setRootAppNewData(""); logTask.setRootAppNewData(hzyaExtData);
//saveTaskLog(); PayResponseDTO payResponseDTO = PayResponseDTO.payResValueOf(decryptRes);
//为true是成功
if (payResponseDTO.getSuccessed()) {
taskLivingDetailsService.saveLogToSuccess(logTask);
}else {
taskLivingDetailsService.saveLogToFail(logTask);
}
} catch (Exception e) {
logger.info("payApplyCallBack方法执行出错:{}",e);
}
} }
/** /**
@ -101,8 +128,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
@Override @Override
public SysExtensionApiEntity agentPayApply(SysExtensionApiEntity entity) { public SysExtensionApiEntity agentPayApply(SysExtensionApiEntity entity) {
String boyds = entity.getBodys(); String boyds = entity.getBodys();
if (StrUtil.isNotEmpty(boyds)){ if (StrUtil.isNotEmpty(boyds)) {
AgentPayRequestDTO agentPayRequest = JSONObject.parseObject(boyds,AgentPayRequestDTO.class); AgentPayRequestDTO agentPayRequest = JSONObject.parseObject(boyds, AgentPayRequestDTO.class);
String requestData = JSONObject.toJSONString(agentPayRequest); String requestData = JSONObject.toJSONString(agentPayRequest);
//加密签名 //加密签名
encrypAndsign(entity, requestData); encrypAndsign(entity, requestData);
@ -119,13 +146,13 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
@Override @Override
public SysExtensionApiEntity payResult(SysExtensionApiEntity entity) { public SysExtensionApiEntity payResult(SysExtensionApiEntity entity) {
String bodys = entity.getBodys(); String bodys = entity.getBodys();
if (StrUtil.isNotEmpty(bodys)){ if (StrUtil.isNotEmpty(bodys)) {
PayResultRequestDTO payResultRequest = JSONObject.parseObject(bodys,PayResultRequestDTO.class); PayResultRequestDTO payResultRequest = JSONObject.parseObject(bodys, PayResultRequestDTO.class);
if (null != payResultRequest && StrUtil.isNotEmpty(payResultRequest.getReferenceNum())){ if (null != payResultRequest && StrUtil.isNotEmpty(payResultRequest.getReferenceNum())) {
String requestData = JSONObject.toJSONString(payResultRequest); String requestData = JSONObject.toJSONString(payResultRequest);
//加密 签名 //加密 签名
encrypAndsign(entity,requestData); encrypAndsign(entity, requestData);
}else { } else {
throw new BaseSystemException("业务参考号不能为空!!!!"); throw new BaseSystemException("业务参考号不能为空!!!!");
} }
} }
@ -141,8 +168,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
@Override @Override
public SysExtensionApiEntity transactionDetailQuery(SysExtensionApiEntity entity) { public SysExtensionApiEntity transactionDetailQuery(SysExtensionApiEntity entity) {
String bodys = entity.getBodys(); String bodys = entity.getBodys();
if (StrUtil.isNotEmpty(bodys)){ if (StrUtil.isNotEmpty(bodys)) {
TransactionDetailReqDTO transactionDetailReqDTO = JSONObject.parseObject(bodys,TransactionDetailReqDTO.class); TransactionDetailReqDTO transactionDetailReqDTO = JSONObject.parseObject(bodys, TransactionDetailReqDTO.class);
String requestData = JSONObject.toJSONString(transactionDetailReqDTO); String requestData = JSONObject.toJSONString(transactionDetailReqDTO);
////加密签名 ////加密签名
encrypAndsign(entity, requestData); encrypAndsign(entity, requestData);
@ -159,8 +186,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
@Override @Override
public SysExtensionApiEntity payApplyAgent(SysExtensionApiEntity entity) { public SysExtensionApiEntity payApplyAgent(SysExtensionApiEntity entity) {
String bodys = entity.getBodys(); String bodys = entity.getBodys();
if (StrUtil.isNotEmpty(bodys)){ if (StrUtil.isNotEmpty(bodys)) {
AgentPayRequestDTO agentPayRequest = JSONObject.parseObject(bodys,AgentPayRequestDTO.class); AgentPayRequestDTO agentPayRequest = JSONObject.parseObject(bodys, AgentPayRequestDTO.class);
String requestData = JSONObject.toJSONString(agentPayRequest); String requestData = JSONObject.toJSONString(agentPayRequest);
////加密签名 ////加密签名
encrypAndsign(entity, requestData); encrypAndsign(entity, requestData);
@ -169,7 +196,6 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
} }
/** /**
* 代发代扣结果查询 * 代发代扣结果查询
* *
@ -179,10 +205,10 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
@Override @Override
public SysExtensionApiEntity payApplyAgentResult(SysExtensionApiEntity entity) { public SysExtensionApiEntity payApplyAgentResult(SysExtensionApiEntity entity) {
String bodys = entity.getBodys(); String bodys = entity.getBodys();
if (StrUtil.isNotEmpty(bodys)){ if (StrUtil.isNotEmpty(bodys)) {
AgentPayResultRequestDTO agentPayResultRequestDTO = JSONObject.parseObject(bodys,AgentPayResultRequestDTO.class); AgentPayResultRequestDTO agentPayResultRequestDTO = JSONObject.parseObject(bodys, AgentPayResultRequestDTO.class);
String requestData = JSONObject.toJSONString(agentPayResultRequestDTO); String requestData = JSONObject.toJSONString(agentPayResultRequestDTO);
encrypAndsign(entity,requestData); encrypAndsign(entity, requestData);
} }
return entity; return entity;
} }
@ -196,11 +222,11 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
@Override @Override
public SysExtensionApiEntity elecQuery(SysExtensionApiEntity entity) { public SysExtensionApiEntity elecQuery(SysExtensionApiEntity entity) {
String bodys = entity.getBodys(); String bodys = entity.getBodys();
if (StrUtil.isNotEmpty(bodys)){ if (StrUtil.isNotEmpty(bodys)) {
ElecRequestDTO elecRequestDTO = JSONObject.parseObject(bodys,ElecRequestDTO.class); ElecRequestDTO elecRequestDTO = JSONObject.parseObject(bodys, ElecRequestDTO.class);
String requestData = JSONObject.toJSONString(elecRequestDTO); String requestData = JSONObject.toJSONString(elecRequestDTO);
//加密 签名 //加密 签名
encrypAndsign(entity,requestData); encrypAndsign(entity, requestData);
} }
return entity; return entity;
} }
@ -208,32 +234,35 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
/** /**
* 请求头 * 请求头
*
* @param sign * @param sign
* @param timestamp * @param timestamp
* @return * @return
*/ */
private Map<String,String> headersValueOf(String sign, long timestamp){ private Map<String, String> headersValueOf(String sign, long timestamp) {
Map<String,String> header = new HashMap(); Map<String, String> header = new HashMap();
header.put(CBSUtil.SIGN_HEADER_NAME,sign); header.put(CBSUtil.SIGN_HEADER_NAME, sign);
header.put(CBSUtil.TIMESTAMP_HEADER,Long.toString(timestamp)); header.put(CBSUtil.TIMESTAMP_HEADER, Long.toString(timestamp));
header.put(HTTP.CONTENT_TYPE,CBSUtil.TARGET_CONTENT_TYPE); header.put(HTTP.CONTENT_TYPE, CBSUtil.TARGET_CONTENT_TYPE);
header.put(CBSUtil.AUTHORIZATION,CBSUtil.BEARER+ CbsAccessToken.getToken()); header.put(CBSUtil.AUTHORIZATION, CBSUtil.BEARER + CbsAccessToken.getToken());
return header; return header;
} }
/** /**
* 加密 签名 * 加密 签名
*
* @param entity 接口转发参数对象 * @param entity 接口转发参数对象
* @param requestData 请求参数json字符串 * @param requestData 请求参数json字符串
*/ */
private void encrypAndsign(SysExtensionApiEntity entity, String requestData) { private void encrypAndsign(SysExtensionApiEntity entity, String requestData) {
//签名 //签名
long timestamp = System.currentTimeMillis(); long timestamp = System.currentTimeMillis();
logger.info("CBS请求参数明文:{}",requestData); logger.info("CBS请求参数明文:{}", requestData);
String sign = CBSUtil.sign(requestData,timestamp); String sign = CBSUtil.sign(requestData, timestamp);
//加密 //加密
byte[] encryptedData = CBSUtil.encrypt(requestData); byte[] encryptedData = CBSUtil.encrypt(requestData);
Map<String,String> header = headersValueOf(sign,timestamp); Map<String, String> header = headersValueOf(sign, timestamp);
header.put("hzyaExtData", requestData);
entity.setByteBodys(encryptedData); entity.setByteBodys(encryptedData);
entity.setHeaders(header); entity.setHeaders(header);
} }

View File

@ -47,17 +47,18 @@ 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 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); String result = decryptResBody(body);
if (StrUtil.isNotEmpty(result)){ PayResponseDTO payResponseDTO = PayResponseDTO.payResValueOf(result);
CbsResponseDTO cbsResponseDTO = JSONObject.parseObject(result, CbsResponseDTO.class); // if (StrUtil.isNotEmpty(result)){
List<JSONObject> dataList = cbsResponseDTO.getData(); // CbsResponseDTO cbsResponseDTO = JSONObject.parseObject(result, CbsResponseDTO.class);
if (CollectionUtils.isNotEmpty(dataList)){ // List<JSONObject> dataList = cbsResponseDTO.getData();
JSONObject o = dataList.get(0); // if (CollectionUtils.isNotEmpty(dataList)){
PayResponseDTO payResponseDTO = JSON.toJavaObject(o, PayResponseDTO.class); // JSONObject o = dataList.get(0);
// PayResponseDTO payResponseDTO = JSON.toJavaObject(o, PayResponseDTO.class);
// return payResponseDTO;
// }
// }
return payResponseDTO; return payResponseDTO;
} }
}
return new PayResponseDTO();
}
/** /**
* 通过业务参考号查询交易结果 3.2.6 * 通过业务参考号查询交易结果 3.2.6
@ -205,17 +206,18 @@ public class Cbs8ServiceImpl implements ICbs8Service {
.build(); .build();
String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterfaceToESB").addHeaders(headerMap).body(params).timeout(60000).execute().body(); String body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterfaceToESB").addHeaders(headerMap).body(params).timeout(60000).execute().body();
String result = decryptResBody(body); String result = decryptResBody(body);
if (StrUtil.isNotEmpty(result)){ PayResponseDTO payResponseDTO = PayResponseDTO.payResValueOf(result);
CbsResponseDTO cbsResponseDTO = JSONObject.parseObject(result, CbsResponseDTO.class); // if (StrUtil.isNotEmpty(result)){
List<JSONObject> dataList = cbsResponseDTO.getData(); // CbsResponseDTO cbsResponseDTO = JSONObject.parseObject(result, CbsResponseDTO.class);
if (CollectionUtils.isNotEmpty(dataList)){ // List<JSONObject> dataList = cbsResponseDTO.getData();
JSONObject o = dataList.get(0); // if (CollectionUtils.isNotEmpty(dataList)){
PayResponseDTO payResponseDTO = JSON.toJavaObject(o, PayResponseDTO.class); // JSONObject o = dataList.get(0);
// PayResponseDTO payResponseDTO = JSON.toJavaObject(o, PayResponseDTO.class);
// return payResponseDTO;
// }
// }
return payResponseDTO; return payResponseDTO;
} }
}
return new PayResponseDTO();
}
/** /**
* 代发代扣 详情查询 * 代发代扣 详情查询