保存日志
This commit is contained in:
parent
9fd9436d94
commit
25696996d7
|
@ -1,5 +1,12 @@
|
|||
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节点
|
||||
* @Author xiangerlin
|
||||
|
@ -70,4 +77,22 @@ public class PayResponseDTO {
|
|||
public void setSuccessed(Boolean 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.convert.Convert;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.util.CBSUtil;
|
||||
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.sysnew.application.entity.SysExtensionApiEntity;
|
||||
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.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.*;
|
||||
|
||||
/**
|
||||
|
@ -29,6 +32,8 @@ import java.util.*;
|
|||
public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private IIntegrationTaskLivingDetailsService taskLivingDetailsService;
|
||||
|
||||
/**
|
||||
* 支付经办
|
||||
*
|
||||
|
@ -38,11 +43,11 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
@Override
|
||||
public SysExtensionApiEntity payApply(SysExtensionApiEntity entity) {
|
||||
String bodys = entity.getBodys();
|
||||
if (StrUtil.isNotEmpty(bodys)){
|
||||
PaymentEntity paymentEntity = JSONObject.parseObject(bodys,PaymentEntity.class);
|
||||
if (null != paymentEntity){
|
||||
if (StrUtil.isNotEmpty(bodys)) {
|
||||
PaymentEntity paymentEntity = JSONObject.parseObject(bodys, PaymentEntity.class);
|
||||
if (null != paymentEntity) {
|
||||
PayRequestDTO payRequestDTO = new PayRequestDTO();
|
||||
String ferenceNum = Convert.toStr(paymentEntity.getReferenceNumNew(),paymentEntity.getReferenceNum());
|
||||
String ferenceNum = Convert.toStr(paymentEntity.getReferenceNumNew(), paymentEntity.getReferenceNum());
|
||||
payRequestDTO.setReferenceNum(ferenceNum);
|
||||
payRequestDTO.setBusType(paymentEntity.getBusType());
|
||||
payRequestDTO.setAmount(paymentEntity.getAmount());
|
||||
|
@ -56,7 +61,7 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
payRequestDTO.setPurpose(paymentEntity.getPurpose());
|
||||
payRequestDTO.setErpExtend1(paymentEntity.getPayType());
|
||||
//集中支付模式
|
||||
if (CBSUtil.CENTRALIZED_PAYMENT_TYPE.equals(payRequestDTO.getBusType())){
|
||||
if (CBSUtil.CENTRALIZED_PAYMENT_TYPE.equals(payRequestDTO.getBusType())) {
|
||||
payRequestDTO.setBusiStep("1");
|
||||
payRequestDTO.setApplyUnitCode(paymentEntity.getPayCompanyCode());
|
||||
payRequestDTO.setPayAccount(null);
|
||||
|
@ -64,8 +69,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
List<PayRequestDTO> list = Arrays.asList(payRequestDTO);
|
||||
String requestData = JSONObject.toJSONString(list);
|
||||
//加密 签名
|
||||
encrypAndsign(entity,requestData);
|
||||
entity.setBodys(JSONObject.toJSONString(payRequestDTO));
|
||||
encrypAndsign(entity, requestData);
|
||||
entity.setBodys(requestData);
|
||||
}
|
||||
}
|
||||
return entity;
|
||||
|
@ -78,18 +83,40 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
*/
|
||||
@Override
|
||||
public void payApplyCallBack(SysMessageManageLogEntity logEntity) {
|
||||
//todo 这里要验证一下bodys里有没有数据
|
||||
logger.info("回调方法里的参数:{}",JSONObject.toJSONString(logEntity));
|
||||
//6、记录系统日志
|
||||
IntegrationTaskLivingDetailsEntity logTask = new IntegrationTaskLivingDetailsEntity();
|
||||
//logTask.setRootAppPk(pay.getFormsonId());
|
||||
//logTask.setRootAppBill(pay.getReferenceNum());
|
||||
//对方接口返回信息
|
||||
//logTask.setNewTransmitInfo(JSONObject.toJSONString(payResponseDTO));
|
||||
logTask.setNewPushDate(new Date());
|
||||
//调用接口请求参数
|
||||
logTask.setRootAppNewData("");
|
||||
//saveTaskLog();
|
||||
try {
|
||||
//todo 这里要验证一下bodys里有没有数据
|
||||
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、记录系统日志
|
||||
IntegrationTaskLivingDetailsEntity logTask = new IntegrationTaskLivingDetailsEntity();
|
||||
logTask.setRootAppPk(sourceBody.getString("formsonId"));
|
||||
logTask.setRootAppBill(sourceBody.getString("referenceNum"));
|
||||
logTask.setPluginId("CBS8PayApplyPlugin");
|
||||
//对方接口返回信息
|
||||
logTask.setNewTransmitInfo(decryptRes);
|
||||
logTask.setNewPushDate(new Date());
|
||||
//调用接口请求参数
|
||||
logTask.setRootAppNewData(hzyaExtData);
|
||||
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
|
||||
public SysExtensionApiEntity agentPayApply(SysExtensionApiEntity entity) {
|
||||
String boyds = entity.getBodys();
|
||||
if (StrUtil.isNotEmpty(boyds)){
|
||||
AgentPayRequestDTO agentPayRequest = JSONObject.parseObject(boyds,AgentPayRequestDTO.class);
|
||||
if (StrUtil.isNotEmpty(boyds)) {
|
||||
AgentPayRequestDTO agentPayRequest = JSONObject.parseObject(boyds, AgentPayRequestDTO.class);
|
||||
String requestData = JSONObject.toJSONString(agentPayRequest);
|
||||
//加密签名
|
||||
encrypAndsign(entity, requestData);
|
||||
|
@ -119,13 +146,13 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
@Override
|
||||
public SysExtensionApiEntity payResult(SysExtensionApiEntity entity) {
|
||||
String bodys = entity.getBodys();
|
||||
if (StrUtil.isNotEmpty(bodys)){
|
||||
PayResultRequestDTO payResultRequest = JSONObject.parseObject(bodys,PayResultRequestDTO.class);
|
||||
if (null != payResultRequest && StrUtil.isNotEmpty(payResultRequest.getReferenceNum())){
|
||||
if (StrUtil.isNotEmpty(bodys)) {
|
||||
PayResultRequestDTO payResultRequest = JSONObject.parseObject(bodys, PayResultRequestDTO.class);
|
||||
if (null != payResultRequest && StrUtil.isNotEmpty(payResultRequest.getReferenceNum())) {
|
||||
String requestData = JSONObject.toJSONString(payResultRequest);
|
||||
//加密 签名
|
||||
encrypAndsign(entity,requestData);
|
||||
}else {
|
||||
encrypAndsign(entity, requestData);
|
||||
} else {
|
||||
throw new BaseSystemException("业务参考号不能为空!!!!");
|
||||
}
|
||||
}
|
||||
|
@ -141,8 +168,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
@Override
|
||||
public SysExtensionApiEntity transactionDetailQuery(SysExtensionApiEntity entity) {
|
||||
String bodys = entity.getBodys();
|
||||
if (StrUtil.isNotEmpty(bodys)){
|
||||
TransactionDetailReqDTO transactionDetailReqDTO = JSONObject.parseObject(bodys,TransactionDetailReqDTO.class);
|
||||
if (StrUtil.isNotEmpty(bodys)) {
|
||||
TransactionDetailReqDTO transactionDetailReqDTO = JSONObject.parseObject(bodys, TransactionDetailReqDTO.class);
|
||||
String requestData = JSONObject.toJSONString(transactionDetailReqDTO);
|
||||
////加密签名
|
||||
encrypAndsign(entity, requestData);
|
||||
|
@ -159,8 +186,8 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
@Override
|
||||
public SysExtensionApiEntity payApplyAgent(SysExtensionApiEntity entity) {
|
||||
String bodys = entity.getBodys();
|
||||
if (StrUtil.isNotEmpty(bodys)){
|
||||
AgentPayRequestDTO agentPayRequest = JSONObject.parseObject(bodys,AgentPayRequestDTO.class);
|
||||
if (StrUtil.isNotEmpty(bodys)) {
|
||||
AgentPayRequestDTO agentPayRequest = JSONObject.parseObject(bodys, AgentPayRequestDTO.class);
|
||||
String requestData = JSONObject.toJSONString(agentPayRequest);
|
||||
////加密签名
|
||||
encrypAndsign(entity, requestData);
|
||||
|
@ -169,7 +196,6 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 代发代扣结果查询
|
||||
*
|
||||
|
@ -179,10 +205,10 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
@Override
|
||||
public SysExtensionApiEntity payApplyAgentResult(SysExtensionApiEntity entity) {
|
||||
String bodys = entity.getBodys();
|
||||
if (StrUtil.isNotEmpty(bodys)){
|
||||
AgentPayResultRequestDTO agentPayResultRequestDTO = JSONObject.parseObject(bodys,AgentPayResultRequestDTO.class);
|
||||
if (StrUtil.isNotEmpty(bodys)) {
|
||||
AgentPayResultRequestDTO agentPayResultRequestDTO = JSONObject.parseObject(bodys, AgentPayResultRequestDTO.class);
|
||||
String requestData = JSONObject.toJSONString(agentPayResultRequestDTO);
|
||||
encrypAndsign(entity,requestData);
|
||||
encrypAndsign(entity, requestData);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
@ -196,11 +222,11 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
@Override
|
||||
public SysExtensionApiEntity elecQuery(SysExtensionApiEntity entity) {
|
||||
String bodys = entity.getBodys();
|
||||
if (StrUtil.isNotEmpty(bodys)){
|
||||
ElecRequestDTO elecRequestDTO = JSONObject.parseObject(bodys,ElecRequestDTO.class);
|
||||
if (StrUtil.isNotEmpty(bodys)) {
|
||||
ElecRequestDTO elecRequestDTO = JSONObject.parseObject(bodys, ElecRequestDTO.class);
|
||||
String requestData = JSONObject.toJSONString(elecRequestDTO);
|
||||
//加密 签名
|
||||
encrypAndsign(entity,requestData);
|
||||
encrypAndsign(entity, requestData);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
@ -208,32 +234,35 @@ public class Cbs8ExtServiceImpl implements ICbs8ExtService {
|
|||
|
||||
/**
|
||||
* 请求头
|
||||
*
|
||||
* @param sign
|
||||
* @param timestamp
|
||||
* @return
|
||||
*/
|
||||
private Map<String,String> headersValueOf(String sign, long timestamp){
|
||||
Map<String,String> header = new HashMap();
|
||||
header.put(CBSUtil.SIGN_HEADER_NAME,sign);
|
||||
header.put(CBSUtil.TIMESTAMP_HEADER,Long.toString(timestamp));
|
||||
header.put(HTTP.CONTENT_TYPE,CBSUtil.TARGET_CONTENT_TYPE);
|
||||
header.put(CBSUtil.AUTHORIZATION,CBSUtil.BEARER+ CbsAccessToken.getToken());
|
||||
private Map<String, String> headersValueOf(String sign, long timestamp) {
|
||||
Map<String, String> header = new HashMap();
|
||||
header.put(CBSUtil.SIGN_HEADER_NAME, sign);
|
||||
header.put(CBSUtil.TIMESTAMP_HEADER, Long.toString(timestamp));
|
||||
header.put(HTTP.CONTENT_TYPE, CBSUtil.TARGET_CONTENT_TYPE);
|
||||
header.put(CBSUtil.AUTHORIZATION, CBSUtil.BEARER + CbsAccessToken.getToken());
|
||||
return header;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密 签名
|
||||
* @param entity 接口转发参数对象
|
||||
*
|
||||
* @param entity 接口转发参数对象
|
||||
* @param requestData 请求参数json字符串
|
||||
*/
|
||||
private void encrypAndsign(SysExtensionApiEntity entity, String requestData) {
|
||||
//签名
|
||||
long timestamp = System.currentTimeMillis();
|
||||
logger.info("CBS请求参数明文:{}",requestData);
|
||||
String sign = CBSUtil.sign(requestData,timestamp);
|
||||
logger.info("CBS请求参数明文:{}", requestData);
|
||||
String sign = CBSUtil.sign(requestData, timestamp);
|
||||
//加密
|
||||
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.setHeaders(header);
|
||||
}
|
||||
|
|
|
@ -47,16 +47,17 @@ 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);
|
||||
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();
|
||||
PayResponseDTO payResponseDTO = PayResponseDTO.payResValueOf(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 payResponseDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -205,16 +206,17 @@ public class Cbs8ServiceImpl implements ICbs8Service {
|
|||
.build();
|
||||
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);
|
||||
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();
|
||||
PayResponseDTO payResponseDTO = PayResponseDTO.payResValueOf(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 payResponseDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue