Commit 5965c219 authored by 5359's avatar 5359

订单结果查询接口代码调整

parent 43d19182
......@@ -264,7 +264,6 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.65.01</version>
<!-- <version>1.47</version>-->
<scope>system</scope>
<systemPath>
${project.basedir}/src/main/webapp/WEB-INF/lib/bcprov-jdk15on-1.65.01.jar
......
package com.chinapay.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.chinapay.comm.Constants;
import com.chinapay.dto.HclcCupSignInfo;
import com.chinapay.dto.HlsEbankCcbTransaction;
import com.chinapay.dto.HlsWsConfig;
import com.chinapay.mapper.HclcCupSignInfoMapper;
import com.chinapay.mapper.HlsEbankCcbTransactionMapper;
import com.chinapay.mapper.HlsWsConfigMapper;
import com.chinapay.secss.SecssConstants;
import com.chinapay.secss.SecssUtil;
import com.chinapay.service.IHclcChinaPayService;
import com.chinapay.service.IHlsEbankCcbTransactionService;
import com.chinapay.util.HttpUtils;
import com.chinapay.util.StringUtil;
import com.hand.app.zhongDengWang.dto.HlsWsRequests;
import com.hand.app.zhongDengWang.mapper.HlsWsRequestsMapper;
import com.hand.hap.core.IRequest;
import com.hand.hap.intergration.service.IHapInterfaceHeaderService;
import com.hand.hap.system.service.impl.BaseServiceImpl;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.*;
......
......@@ -41,9 +41,9 @@ public class HclcCmbPolyListenController extends BaseController {
* @return
*/
@ResponseBody
@RequestMapping("core/api/public/cmb/get/qr/code/listen")
public Map<String, String> orderStatusNotify(HttpServletRequest request,
@RequestBody(required = true) JSONObject params) {
@RequestMapping("/api/public/cmb/get/qr/code/listen")
public JSONObject orderStatusNotify(HttpServletRequest request,
@RequestBody String params) {
IRequest iRequest = createRequestContext(request);
return hclcCmbPolyService.orderNotify(iRequest, params);
......
......@@ -11,7 +11,7 @@ public interface HclcCmbPolyService {
JSONObject queryOrderStatus(IRequest iRequest, JSONObject params);
Map orderNotify(IRequest iRequest, JSONObject params);
JSONObject orderNotify(IRequest iRequest, String params);
JSONObject closeOrder(IRequest iRequest, JSONObject params);
......
package com.hand.app.cmb.service;
import com.hand.app.cmb.dto.HlsEbankCmbTransqry;
import com.hand.hap.core.ProxySelf;
import com.hand.hap.system.service.IBaseService;
/**
* Created with IntelliJ IDEA.
* User: lsy
* Date: 2020/2/24
* Time: 9:08
*/
public interface IHlsEbankCmbTransqryService extends IBaseService<HlsEbankCmbTransqry>, ProxySelf<IHlsEbankCmbTransqryService> {
}
......@@ -6,12 +6,11 @@ import com.chinapay.dto.HlsEbankCcbTransaction;
import com.chinapay.mapper.HlsEbankCcbTransactionMapper;
import com.chinapay.service.IHlsEbankCcbTransactionService;
import com.chinapay.util.StringUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.hand.app.cmb.dto.HlsEbankCmbTransqry;
import com.hand.app.cmb.dto.Ld037;
import com.hand.app.cmb.mapper.HlsEbankCmbTransqryMapper;
import com.hand.app.cmb.mapper.Ld037Mapper;
import com.hand.app.cmb.service.HclcCmbPolyService;
import com.hand.app.cmb.service.IHlsEbankCmbTransqryService;
import com.hand.app.cmb.util.MD5Utils;
import com.hand.app.cmb.util.SM2Util;
import com.hand.app.cmb.util.SignatureUtil;
......@@ -20,10 +19,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.hand.app.esignHclc.utils.SignHclcUtils;
import com.hand.app.zhongDengWang.dto.HlsWsRequests;
import com.hand.app.zhongDengWang.mapper.HlsWsRequestsMapper;
import com.hand.app.zhongDengWang.service.IHlsWsRequestsService;
import com.hand.hap.core.IRequest;
import com.hand.hap.intergration.dto.HapInterfaceHeader;
import com.hand.hap.intergration.service.IHapInterfaceHeaderService;
import org.apache.poi.hssf.record.DVALRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -78,13 +77,13 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
@Autowired
private IHlsEbankCcbTransactionService hlsEbankCcbTransactionService;
@Autowired
private HlsWsRequestsMapper hlsWsRequestsMapper;
private IHlsWsRequestsService hlsWsRequestsService;
@Autowired
private Ld037Mapper ld037Mapper;
@Autowired
private HlsEbankCmbTransqryMapper hlsEbankCmbTransqryMapper;
private IHlsEbankCmbTransqryService hlsEbankCmbTransqryService;
@Autowired
IHapInterfaceHeaderService headerService;
private IHapInterfaceHeaderService headerService;
@Autowired
private DataSourceTransactionManager transactionManager;
......@@ -97,19 +96,17 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
String errorCd = null;
if (Objects.isNull(params.get("recamt_id"))) {
result.put(Constants.RESP_CODE, "E");
result.put(Constants.RESP_CODE, transFail);
result.put("respMsg", "请求必须参数recamt_id缺失,请检查!");
return result;
}
//根据recamt_id查询ld037数据生成hls_ebank_ccb_transaction批次记录
Long recamtId = params.getLong("recamt_id");
Ld037 ld037 = new Ld037();
ld037.setId(recamtId);
ld037 = ld037Mapper.selectByPrimaryKey(ld037);
Ld037 ld037 = ld037Mapper.selectByPrimaryKey(recamtId);
if (Objects.nonNull(ld037.getReceiptstatus())) {
result.put(Constants.RESP_CODE, "E");
result.put(Constants.RESP_CODE, transFail);
result.put("respMsg", "支付订单状态异常,请检查!");
return result;
}
......@@ -117,11 +114,6 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
HlsEbankCcbTransaction hlsEbankCcbTransaction = createTransaction(iRequest, ld037);
ld037.setTransactionId(hlsEbankCcbTransaction.getTransactionId());
//生成单据编号 日期+id
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String dateString = formatter.format(new Date());
hlsEbankCcbTransaction.setTransactionNumber(dateString + String.format("%08d", hlsEbankCcbTransaction.getTransactionId()));
Map<String, String> response = null;
try {
......@@ -153,7 +145,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
apiHeader.put("apisign", apiSignString);
//初始化日志
HlsWsRequests hlsWsRequests = logInterfaceRequest(getQrCode, pro.getProperty("cmb.qrCodeapplyUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
HlsWsRequests hlsWsRequests = logInterfaceRequest(iRequest, getQrCode, pro.getProperty("cmb.qrCodeapplyUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
logger.info("发送收款码申请请求,请求参数: {}", mapper.writeValueAsString(apiHeader));
try {
......@@ -215,7 +207,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
resultType = "5";
}
hlsWsRequestsMapper.updateByPrimaryKeySelective(hlsWsRequests);
hlsWsRequestsService.updateByPrimaryKeySelective(iRequest, hlsWsRequests);
} catch (Exception e) {
e.printStackTrace();
logger.info("组装请求报文信息失败: {} ", e.getMessage());
......@@ -226,10 +218,10 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
errorCd = "MESSAGE_ERROR";
resultType = "5";
}
} finally {
hlsEbankCcbTransaction = setEbankTransaction(hlsEbankCcbTransaction, response, resultType);
hlsEbankCcbTransactionMapper.updateByPrimaryKey(hlsEbankCcbTransaction);
hlsEbankCcbTransactionService.updateByPrimaryKey(iRequest, hlsEbankCcbTransaction);
}
//更新现金事务表ld037失败处理
if (Objects.nonNull(errorCd)) {
......@@ -326,6 +318,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
ccbTransaction.setVersion(pro.getProperty("cmb.version"));
ccbTransaction.setUserId(pro.getProperty("cmb.user.id"));
ccbTransaction.setStatus(transNew);
ccbTransaction.setOrderStatus(orderNo);
ccbTransaction.setBankType("CMB");
ccbTransaction.setCount(1L);
ccbTransaction.setAmount(ld037.getAmount());
......@@ -337,15 +330,14 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
ccbTransaction.setTranTime(StringUtil.getRelevantTime(new Date()));
ccbTransaction.setTranType("APPLY");
hlsEbankCcbTransactionMapper.insert(ccbTransaction);
ccbTransaction = hlsEbankCcbTransactionService.insertSelective(iRequest, ccbTransaction);
// //生成单据编号 日期+id
// SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
// String dateString = formatter.format(new Date());
// ccbTransaction.setTransactionNumber(dateString + String.format("%08d", ccbTransaction.getTransactionId()));
// ccbTransaction = hlsEbankCcbTransactionService.updateByPrimaryKeySelective(iRequest, ccbTransaction);
//生成单据编号 日期+id
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String dateString = formatter.format(new Date());
ccbTransaction.setTransactionNumber(dateString + String.format("%08d", ccbTransaction.getTransactionId()));
return hlsEbankCcbTransactionMapper.selectByPrimaryKey(ccbTransaction);
return ccbTransaction;
}
private String getQrRequestParams(HlsEbankCcbTransaction hlsEbankCcbTransaction, Ld037 ld037) {
......@@ -371,7 +363,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
BigDecimal b1 = new BigDecimal(Double.toString(100));
requestTransactionParams.put("txnAmt", a1.multiply(b1).stripTrailingZeros().toPlainString()); //交易金额,单位为分(必传)
requestTransactionParams.put("currencyCode", pro.getProperty("cmb.currencyCode")); //交易币种,默认156,目前只支持人民币(156)
requestTransactionParams.put("body", "聚合支付测试"); //商户号(必传)
requestTransactionParams.put("body", ld037.getContractno()); //商户号(必传)
//商户保留域
JSONObject mchReserved = new JSONObject();
......@@ -406,26 +398,22 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
JSONObject result = new JSONObject();
//去ld037中查找对应的记录的receiptcfmstatus,
if (Objects.isNull(params.get("recamt_id"))) {
result.put(Constants.RESP_CODE, "E");
result.put(Constants.RESP_CODE, transFail);
result.put("respMsg", "请求必须参数recamt_id缺失,请检查!");
return result;
}
//根据recamt_id查询ld037数据生成hls_ebank_ccb_transaction批次记录
Long recamtId = params.getLong("recamt_id");
Ld037 ld037 = new Ld037();
ld037.setId(recamtId);
ld037 = ld037Mapper.selectByPrimaryKey(ld037);
Ld037 ld037 = ld037Mapper.selectByPrimaryKey(recamtId);
//与查询二维码有区别,查询二维码时订单并未创建,但查询订单状态时,订单记录已经在数据库中有记录,
// 所以只需要通过recamt_id在ld037表中查到对应的订单记录,
// 然后通过ld037表中的transaction_id找到对应的hlsEbankCcbTransaction对象
HlsEbankCcbTransaction hlsEbankCcbTransaction = new HlsEbankCcbTransaction();
hlsEbankCcbTransaction.setTransactionId(ld037.getTransactionId());
hlsEbankCcbTransaction = hlsEbankCcbTransactionMapper.selectByPrimaryKey(hlsEbankCcbTransaction);
HlsEbankCcbTransaction hlsEbankCcbTransaction = hlsEbankCcbTransactionMapper.selectByPrimaryKey(ld037.getTransactionId());
if (Objects.isNull(hlsEbankCcbTransaction) || "CMB".equalsIgnoreCase(hlsEbankCcbTransaction.getBankType())) {
result.put(Constants.RESP_CODE, "S");
if (Objects.isNull(hlsEbankCcbTransaction) || !"CMB".equalsIgnoreCase(hlsEbankCcbTransaction.getBankType())) {
result.put(Constants.RESP_CODE, tranSuccess);
result.put(Constants.RESP_MSG, "订单不存在");
//给到前端订单的状态
result.put("tradeState", orderNo);
......@@ -433,7 +421,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
}
if (!transDeal.equalsIgnoreCase(hlsEbankCcbTransaction.getStatus())) {
result.put(Constants.RESP_CODE, "S");
result.put(Constants.RESP_CODE, tranSuccess);
result.put(Constants.RESP_MSG, "查询成功");
//给到前端订单的状态
result.put("tradeState", hlsEbankCcbTransaction.getOrderStatus());
......@@ -447,12 +435,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
TransactionStatus transactionStatus = transactionManager.getTransaction(def);
//创建订单查询记录
HlsEbankCmbTransqry hlsEbankCmbTransqry = createTransqry(hlsEbankCcbTransaction.getTransactionId(), "GET");
//生成单据编号 日期+id
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String dateString = formatter.format(new Date());
hlsEbankCmbTransqry.setTransqryNumber(dateString + String.format("%08d", hlsEbankCcbTransaction.getTransactionId()));
HlsEbankCmbTransqry hlsEbankCmbTransqry = createTransqry(iRequest, hlsEbankCcbTransaction.getTransactionId(), "GET");
Map<String, String> responseMap = null;
try {
......@@ -483,7 +466,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
apiHeader.put("apisign", apiSignString);
//初始化日志
HlsWsRequests hlsWsRequests = logInterfaceRequest(queryQrState, pro.getProperty("cmb.orderQueryUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
HlsWsRequests hlsWsRequests = logInterfaceRequest(iRequest, queryQrState, pro.getProperty("cmb.orderQueryUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
try {
//发送http请求
responseMap = Utils.postForEntity(pro.getProperty("cmb.orderQueryUrl"), signResult, apiHeader);
......@@ -504,7 +487,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
String respCode = responseMap.get("respCode");
if ("SUCCESS".equalsIgnoreCase(respCode)) {
//成功拿到订单状态请求的响应
hlsEbankCmbTransqry = finishTransaction(responseMap, hlsEbankCcbTransaction, hlsEbankCmbTransqry);
hlsEbankCmbTransqry = finishTransaction(iRequest, responseMap, hlsEbankCcbTransaction, hlsEbankCmbTransqry);
resultType = "7";
} else {
......@@ -520,6 +503,14 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
resultType = "6";
}
} else {
if("CMBORDERID_NOT_EXIST".equalsIgnoreCase(responseMap.get("errCode"))){
//关闭订单
hlsEbankCcbTransaction.setStatus(transClose);
hlsEbankCcbTransaction.setOrderStatus("C");
hlsEbankCcbTransactionMapper.updateByPrimaryKey(hlsEbankCcbTransaction);
//更新
updateLd037Fail(ld037, responseMap.get("errCode"));
}
//请求成功,但是响应结果为失败,传给前端失败原因就行
resultType = "2";
}
......@@ -550,7 +541,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//更新log日志表
hlsWsRequests.setResponsedDate(new Date());
hlsWsRequestsMapper.updateByPrimaryKeySelective(hlsWsRequests);
hlsWsRequestsService.updateByPrimaryKeySelective(iRequest, hlsWsRequests);
} catch (Exception e) {
e.printStackTrace();
......@@ -565,8 +556,10 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
}
//设置查询失败结果信息
if (!"7".equalsIgnoreCase(resultType)) {
hlsEbankCmbTransqry = setEbankTransqry(hlsEbankCmbTransqry, responseMap, resultType);
hlsEbankCmbTransqryMapper.updateByPrimaryKeySelective(hlsEbankCmbTransqry);
}
hlsEbankCmbTransqryService.updateByPrimaryKeySelective(iRequest, hlsEbankCmbTransqry);
//状态刷新
transactionStatus.flush();
......@@ -585,7 +578,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
}
//生成招行扫码交易业务批次数据
private HlsEbankCmbTransqry createTransqry(Long transactionId, String queryCategory) {
private HlsEbankCmbTransqry createTransqry(IRequest iRequest, Long transactionId, String queryCategory) {
HlsEbankCmbTransqry cmbTransqry = new HlsEbankCmbTransqry();
cmbTransqry.setMerId(pro.getProperty("cmb.mer.id"));
cmbTransqry.setVersion(pro.getProperty("cmb.version"));
......@@ -595,9 +588,14 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
cmbTransqry.setCreationDate(new Date());
cmbTransqry.setLastUpdatedBy(1L);
cmbTransqry.setQueryCategory(queryCategory);
hlsEbankCmbTransqryMapper.insert(cmbTransqry);
cmbTransqry = hlsEbankCmbTransqryService.insert(iRequest, cmbTransqry);
//生成单据编号 日期+id
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String dateString = formatter.format(new Date());
cmbTransqry.setTransqryNumber(dateString + String.format("%08d", cmbTransqry.getTransqryId()));
return hlsEbankCmbTransqryMapper.selectByPrimaryKey(cmbTransqry);
return cmbTransqry;
}
private String postWriteLd037(JSONObject params) {
......@@ -638,22 +636,23 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
}
//订单完成通用接口
private HlsEbankCmbTransqry finishTransaction(Map<String, String> responseMap, HlsEbankCcbTransaction hlsEbankCcbTransaction, HlsEbankCmbTransqry hlsEbankCmbTransqry) {
private HlsEbankCmbTransqry finishTransaction(IRequest iRequest, Map<String, String> responseMap, HlsEbankCcbTransaction hlsEbankCcbTransaction, HlsEbankCmbTransqry hlsEbankCmbTransqry) {
//更新交易事务表数据
JSONObject bizContent = JSONObject.parseObject(responseMap.get("biz_content"));
if (Objects.nonNull(bizContent.getString("tradeState"))) {
if (!"P".equalsIgnoreCase(bizContent.getString("tradeState"))) {
if (!orderPass.equalsIgnoreCase(bizContent.getString("tradeState"))) {
hlsEbankCcbTransaction.setStatus(tranSuccess);
hlsEbankCcbTransaction.setSuccessDate(new Date());
}
if ("S".equalsIgnoreCase(bizContent.getString("tradeState"))) {
if (orderSuccess.equalsIgnoreCase(bizContent.getString("tradeState"))) {
hlsEbankCcbTransaction.setSuccessAmount(hlsEbankCcbTransaction.getAmount());
hlsEbankCcbTransaction.setSuccessCount(hlsEbankCcbTransaction.getCount());
}
}
hlsEbankCcbTransaction.setOrderStatus(bizContent.getString("tradeState"));
hlsEbankCcbTransactionMapper.updateByPrimaryKeySelective(hlsEbankCcbTransaction);
hlsEbankCcbTransactionService.updateByPrimaryKeySelective(iRequest, hlsEbankCcbTransaction);
}
}
//更新查询表数据
hlsEbankCmbTransqry.setReturnCode(responseMap.get("respCode"));
......@@ -808,12 +807,10 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
}
@Override
public Map<String, String> orderNotify(IRequest iRequest, JSONObject params) {
JSONObject result = new JSONObject();
System.out.println(params);
String requestBodyString = params.toJSONString();
Map<String, String> respData = new HashMap<>();
public JSONObject orderNotify(IRequest iRequest, String requestBodyString) {
JSONObject respData = new JSONObject();
logger.info("支付结果通知,通知信息requestBodyString:" + requestBodyString);
//设置响应数据
respData.put("version", pro.getProperty("cmb.version"));//版本号,固定为0.0.1(必传)
respData.put("encoding", pro.getProperty("cmb.encoding"));//编码方式,固定为UTF-8(必传)
......@@ -825,7 +822,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
respData.put("returnCode", "FAIL");
return respData;
}
Map<String, String> requestBodyMap = str2Map(requestBodyString);
Map<String, String> requestBodyMap = Utils.str2Map(SignatureUtil.decode(requestBodyString));
Map<String, String> resultMap = requestBodyMap.entrySet().stream().collect(Collectors.toMap(e -> SignatureUtil.decode(e.getKey()), e -> SignatureUtil.decode(e.getValue())));
if (resultMap == null) {
respData.put("returnCode", "FAIL");
......@@ -838,77 +835,98 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
boolean flag = SM2Util.sm2Check(contentStr, sign, pro.getProperty("cmb.publicKey"));
if (!flag) {
//验签失败
System.out.println("验签失败");
logger.info("验签失败");
respData.put("returnCode", "FAIL");
return respData;
}
System.out.println("验签成功");
logger.info("验签成功");
JSONObject mchReserved = params.getJSONObject("mchReserved");
JSONObject mchReserved = JSONObject.parseObject(resultMap.get("biz_content")).getJSONObject("mchReserved");
Long recamtId = mchReserved.getLong("recamt_id");
Ld037 ld037 = new Ld037();
ld037.setId(recamtId);
ld037 = ld037Mapper.selectByPrimaryKey(ld037);
Ld037 ld037 = ld037Mapper.selectByPrimaryKey(recamtId);
/*对请求结果进行保存*/
HlsEbankCcbTransaction hlsEbankCcbTransaction = hlsEbankCcbTransactionMapper.selectByPrimaryKey(ld037.getTransactionId());
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
// 事务隔离级别:开启新事务
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
//对于每次请求都开启一个事物
TransactionStatus transactionStatus = transactionManager.getTransaction(def);
//创建订单查询记录
HlsEbankCmbTransqry hlsEbankCmbTransqry = createTransqry(hlsEbankCcbTransaction.getTransactionId(), "POST");
//生成单据编号 日期+id
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String dateString = formatter.format(new Date());
hlsEbankCmbTransqry.setTransqryNumber(dateString + String.format("%08d", hlsEbankCcbTransaction.getTransactionId()));
hlsEbankCmbTransqry = finishTransaction(resultMap,hlsEbankCcbTransaction,hlsEbankCmbTransqry);
hlsEbankCmbTransqryMapper.updateByPrimaryKey(hlsEbankCmbTransqry);
hlsWsRequestsMapper.updateByPrimaryKey(logInterfaceRequest(queryQrState, pro.getProperty("cmb.server"), new ObjectMapper().writeValueAsString(respData), hlsEbankCcbTransaction.getTransactionId()));
HlsEbankCmbTransqry hlsEbankCmbTransqry = createTransqry(iRequest, hlsEbankCcbTransaction.getTransactionId(), "POST");
JSONObject biz_content=JSONObject.parseObject(resultMap.get("biz_content"));
biz_content.put("tradeState",orderSuccess);
resultMap.put("biz_content",biz_content.toJSONString());
hlsEbankCmbTransqry = finishTransaction(iRequest, resultMap, hlsEbankCcbTransaction, hlsEbankCmbTransqry);
//设置结果信息
hlsEbankCmbTransqryService.updateByPrimaryKeySelective(iRequest, hlsEbankCmbTransqry);
//状态刷新
transactionStatus.flush();
//事务提交
transactionManager.commit(transactionStatus);
JSONObject ld037Param = new JSONObject();
ld037Param.put("transaction_id", hlsEbankCcbTransaction.getTransactionId());
postWriteLd037(ld037Param);
respData.put("respCode", "SUCCESS");//业务错误码,成功为SUCCESS,失败为FAIL
/*如果处理自身业务逻辑发生错误,返回
respData.put("respCode","FAIL");
respData.put("respMsg","error_msg");
*/
//对待加签内容进行排序拼接
String signContent = SignatureUtil.getSignContent(respData);
String signContent = SignatureUtil.getSignContent(Utils.JsonToMap(respData));
//加签-使用商户私钥加签
respData.put("sign", SM2Util.sm2Sign(signContent, pro.getProperty("cmb.privateKey")));
return respData;
} catch (Exception e) {
e.printStackTrace();
respData.put("returnCode", "FAIL");
return respData;
}
return respData;
}
@Override
public JSONObject closeOrder(IRequest iRequest, JSONObject params) {
JSONObject result = new JSONObject();
if (Objects.isNull(params.get("recamt_id"))) {
result.put(Constants.RESP_CODE, "E");
result.put(Constants.RESP_CODE, transFail);
result.put("respMsg", "请求必须参数recamt_id缺失,请检查!");
return result;
}
//根据recamt_id查询ld037数据生成hls_ebank_ccb_transaction批次记录
Long recamtId = params.getLong("recamt_id");
Ld037 ld037 = new Ld037();
ld037.setId(recamtId);
ld037 = ld037Mapper.selectByPrimaryKey(ld037);
Ld037 ld037 = ld037Mapper.selectByPrimaryKey(recamtId);
HlsEbankCcbTransaction hlsEbankCcbTransaction = hlsEbankCcbTransactionMapper.selectByPrimaryKey(ld037.getTransactionId());
if (Objects.isNull(hlsEbankCcbTransaction) || !"CMB".equalsIgnoreCase(hlsEbankCcbTransaction.getBankType())) {
result.put(Constants.RESP_CODE, transFail);
result.put(Constants.RESP_MSG, "订单不存在");
return result;
}
/**
* 支付成功的订单不允许关单,需要修改返回代码
* 非交易在进行的订单不允许关单,需要修改返回代码
*/
if ("SUCCESS".equalsIgnoreCase(hlsEbankCcbTransaction.getStatus())) {
result.put(Constants.RESP_CODE, "E");
result.put("respMsg", "订单已经支付成功!");
if (orderPass.equalsIgnoreCase(hlsEbankCcbTransaction.getOrderStatus())) {
result.put(Constants.RESP_CODE, transFail);
result.put("respMsg", "订单状态异常,无法关闭!");
return result;
}
Map<String, String> responseMap = null;
try {
//开始封装请求部分
String signResult = getOrderCloseParameter(hlsEbankCcbTransaction);
ObjectMapper mapper = new ObjectMapper();
Map<String, String> apiHeader = null;
try {
ObjectMapper mapper = new ObjectMapper();
Map<String, String> signResultMap = mapper.readValue(signResult, Map.class);
long currentTimeMills = System.currentTimeMillis() / 1000;
......@@ -924,26 +942,25 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
String apiSignString = MD5Utils.getMD5Content(MD5Content).toLowerCase();
// 组request头部Map
apiHeader = new HashMap<>();
Map<String, String> apiHeader = new HashMap<>();
apiHeader.put("appid", pro.getProperty("cmb.appId"));
apiHeader.put("timestamp", "" + currentTimeMills);
apiHeader.put("apisign", apiSignString);
} catch (IOException e) {
/// resultType = "5";
e.printStackTrace();
}
HlsWsRequests hlsWsRequests = null;
HlsWsRequests hlsWsRequests = logInterfaceRequest(iRequest, closeOrder, pro.getProperty("cmb.closeUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
try {
hlsWsRequests = logInterfaceRequest(closeOrder, pro.getProperty("cmb.closeUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
Map<String, String> responseMap = Utils.postForEntity(pro.getProperty("cmb.closeUrl"), signResult, apiHeader);
//发送http请求
responseMap = Utils.postForEntity(pro.getProperty("cmb.closeUrl"), signResult, apiHeader);
//处理接口日志
logger.info("关闭订单返回结果:" + mapper.writeValueAsString(responseMap));
hlsWsRequests.setResponseClob(mapper.writeValueAsString(responseMap));
hlsWsRequests.setReturnStatus("S");
//处理响应报文
Boolean checkResponse = checkSign(mapper.writeValueAsString(responseMap));
//数据验签成功
if (checkResponse) {
hlsWsRequests.setResponseClob(mapper.writeValueAsString(responseMap));
hlsWsRequests.setReturnStatus("S");
hlsWsRequests.setResponsedDate(new Date());
//获取返回码,返回码不为SUCCESS表示报文内的字段不符合规范
String returnCode = responseMap.get("returnCode");
if ("SUCCESS".equalsIgnoreCase(returnCode)) {
......@@ -951,51 +968,67 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
String respCode = responseMap.get("respCode");
if ("ORDER_PAID".equalsIgnoreCase(respCode)) {
//需要调用退款接口
result.put(Constants.RESP_CODE, "E");
result.put("respMsg", "需要调用退款接口!");
result.put(Constants.RESP_CODE, transFail);
result.put("respMsg", "订单已支付,无法关闭!");
return result;
} else if ("SUCCESS".equalsIgnoreCase(respCode)) {
//订单关闭成功
if ("C".equalsIgnoreCase(responseMap.get("closeState"))) {
//关闭订单
hlsEbankCcbTransaction.setStatus(transClose);
hlsEbankCcbTransaction.setOrderStatus("C");
hlsEbankCcbTransactionMapper.updateByPrimaryKey(hlsEbankCcbTransaction);
//更新
updateLd037Fail(ld037, "ORDERID_INVALID");
result.put(Constants.RESP_CODE, responseMap.get("respCode"));
result.put(Constants.RESP_MSG, "请求成功");
result.put("cmborderid", responseMap.get("origOrderId"));
result.put("closeState", responseMap.get("closeState"));
result.put("txnTime", responseMap.get("txnTime"));
result.put(Constants.RESP_MSG, "订单关闭成功");
// result.put("cmborderid", responseMap.get("origOrderId"));
// result.put("closeState", responseMap.get("closeState"));
// result.put("txnTime", responseMap.get("txnTime"));
}
//关单失败处理
else {
hlsEbankCcbTransaction.setOrderStatus("F");
// hlsEbankCcbTransaction.setOrderStatus("F");
result.put(Constants.RESP_CODE, responseMap.get("respCode"));
result.put(Constants.RESP_MSG, "请求成功");
result.put("cmborderid", responseMap.get("origOrderId"));
result.put("closeState", responseMap.get("closeState"));
result.put("txnTime", responseMap.get("txnTime"));
result.put(Constants.RESP_MSG, "被关闭交易为失败状态,关单失败");
// result.put("cmborderid", responseMap.get("origOrderId"));
// result.put("closeState", responseMap.get("closeState"));
// result.put("txnTime", responseMap.get("txnTime"));
}
} else if ("SYSTERM_ERROR".equalsIgnoreCase(respCode)) {
//请求成功,但是响应结果为失败,传给前端失败原因就行
result.put(Constants.RESP_CODE, "E");
result.put("respMsg", "需要重新调用查询接口!");
} else if ("FAIL".equalsIgnoreCase(respCode)) {
result.put("errCode", responseMap.get("errCode"));
result.put("respMsg", responseMap.get("respMsg"));
result.put(Constants.RESP_CODE, responseMap.get("errCode"));
result.put(Constants.RESP_MSG, responseMap.get("respMsg"));
}
} else {
//返回码都失败
result.put("errCode", responseMap.get("errCode"));
result.put("respMsg", responseMap.get("respMsg"));
result.put(Constants.RESP_CODE, responseMap.get("errCode"));
result.put(Constants.RESP_MSG, responseMap.get("respMsg"));
}
} else {
result.put(Constants.RESP_CODE, transFail);
result.put(Constants.RESP_MSG, "数据验签失败");
}
} catch (JsonProcessingException e) {
result.put(Constants.RESP_CODE, "E");
result.put("respMsg", "数据验签失败");
} catch (Exception e) {
hlsWsRequests.setReturnStatus("E");
hlsWsRequests.setResponsedDate(new Date());
e.printStackTrace();
logger.info("发送请求异常: {} ", e.getMessage());
result.put(Constants.RESP_CODE, transFail);
result.put(Constants.RESP_MSG, "发送请求异常," + e.getMessage());
}
//更新log日志表
hlsWsRequests.setResponsedDate(new Date());
hlsWsRequestsService.updateByPrimaryKeySelective(iRequest, hlsWsRequests);
} catch (IOException e) {
e.printStackTrace();
logger.info("组装请求报文信息失败: {} ", e.getMessage());
result.put(Constants.RESP_CODE, transFail);
result.put(Constants.RESP_MSG, "组装请求报文信息失败,请查看日志!");
}
hlsEbankCcbTransactionMapper.updateByPrimaryKey(hlsEbankCcbTransaction);
return result;
}
......@@ -1010,12 +1043,13 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//业务要素
Map<String, String> requestTransactionParams = new HashMap<>();
requestTransactionParams.put("merId", hlsEbankCcbTransaction.getMerId()); //商户号(必传)
requestTransactionParams.put("origOrderId", hlsEbankCcbTransaction.getTransactionNumber()); //原交易商户订单号(必传)
requestTransactionParams.put("userId", hlsEbankCcbTransaction.getUserId()); //收银员
ObjectMapper mapper = new ObjectMapper();
requestPublicParams.put("biz_content", mapper.writeValueAsString(requestTransactionParams));
requestTransactionParams.put("origOrderId", hlsEbankCcbTransaction.getTransactionNumber()); //商户订单号(必传)
System.out.println("加签前的报文内容:" + mapper.writeValueAsString(requestPublicParams));
logger.info("加签前的报文内容:" + mapper.writeValueAsString(requestPublicParams));
//对待加签内容进行排序拼接
String signContent = SignatureUtil.getSignContent(requestPublicParams);
......@@ -1024,32 +1058,16 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
requestStr = mapper.writeValueAsString(requestPublicParams);
System.out.println("加签后的报文内容:" + requestStr);
return requestStr;
logger.info("加签后的报文内容:" + requestStr);
} catch (Exception e) {
System.out.println("加签发生异常!");
logger.info("加签发生异常!" + e.getMessage());
e.printStackTrace();
} finally {
return requestStr;
}
}
private Map<String, String> str2Map(String str) {
Map<String, String> result = new HashMap<>();
String[] results = str.split("&");
if (results != null && results.length > 0) {
for (int var = 0; var < results.length; ++var) {
String pair = results[var];
String[] kv = pair.split("=", 2);
if (kv != null && kv.length == 2) {
result.put(kv[0], kv[1]);
}
}
}
return result;
}
private Boolean checkSign(String string) {
System.out.println("要验签的报文内容:" + string);
try {
......@@ -1073,7 +1091,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
}
}
public HlsWsRequests logInterfaceRequest(String functionName, String url, String request, Long pkValue) {
public HlsWsRequests logInterfaceRequest(IRequest iRequest, String functionName, String url, String request, Long pkValue) {
HlsWsRequests hlsWsRequests = new HlsWsRequests();
hlsWsRequests.setRequestDate(new Date());
......@@ -1086,17 +1104,19 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
hlsWsRequests.setStatusDate(new Date());
hlsWsRequests.setPkValue(pkValue);
hlsWsRequests.setRequestClob(request);
hlsWsRequestsMapper.insertSelective(hlsWsRequests);
hlsWsRequests = hlsWsRequestsService.insertSelective(iRequest, hlsWsRequests);
return hlsWsRequests;
}
private String getTableName(String functionName) {
String tableName = "";
if ("GET_QR_CODE".equalsIgnoreCase(functionName)) {
if (getQrCode.equalsIgnoreCase(functionName)) {
tableName = "HLS_EBANK_CCB_TRANSACTION";
} else if ("QUERY_PAY_RESULT".equalsIgnoreCase(functionName)) {
} else if (queryQrState.equalsIgnoreCase(functionName)) {
tableName = "HLS_EBANK_CMB_QUERY";
} else if (closeOrder.equalsIgnoreCase(functionName)) {
tableName = "HLS_EBANK_CMB_CLOSE";
}
return tableName;
......
package com.hand.app.cmb.service.impl;
import com.chinapay.service.IHlsEbankCcbTransactionService;
import com.hand.app.cmb.dto.HlsEbankCmbTransqry;
import com.hand.app.cmb.service.IHlsEbankCmbTransqryService;
import com.hand.hap.system.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
/**
* Created with IntelliJ IDEA.
* User: lsy
* Date: 2020/2/24
* Time: 9:08
*/
@Service
public class HlsEbankCmbTransqryServiceImpl extends BaseServiceImpl<HlsEbankCmbTransqry> implements IHlsEbankCmbTransqryService {
}
\ No newline at end of file
......@@ -171,6 +171,21 @@ public class Utils {
return paramMap;
}
public static Map<String, String> str2Map(String str) {
Map<String, String> result = new HashMap<>();
String[] results = str.split("&");
if (results != null && results.length > 0) {
for (int var = 0; var < results.length; ++var) {
String pair = results[var];
String[] kv = pair.split("=", 2);
if (kv != null && kv.length == 2) {
result.put(kv[0], kv[1]);
}
}
}
return result;
}
/**
* 加载properties配置文件
* @param propPath
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment