Commit ae5c4915 authored by 5359's avatar 5359

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

parent e4df144b
......@@ -80,6 +80,8 @@ public class HlsEbankCcbTransaction extends BaseDTO {
private String txnTime;
private Date successDate;
public Long getTransactionId() {
return transactionId;
}
......@@ -279,4 +281,12 @@ public class HlsEbankCcbTransaction extends BaseDTO {
public void setTxnTime(String txnTime) {
this.txnTime = txnTime;
}
public Date getSuccessDate() {
return successDate;
}
public void setSuccessDate(Date successDate) {
this.successDate = successDate;
}
}
\ No newline at end of file
......@@ -33,9 +33,9 @@ public class HlsEbankCmbTransqry {
private String errDescription;
private Long txnAmt;
private String txnAmt;
private Long dscAmt;
private String dscAmt;
private String currencyCode;
......@@ -69,6 +69,10 @@ public class HlsEbankCmbTransqry {
private Long lastUpdatedBy;
private String status;
private String queryCategory;
public Long getTransqryId() {
return transqryId;
}
......@@ -149,19 +153,19 @@ public class HlsEbankCmbTransqry {
this.errDescription = errDescription;
}
public Long getTxnAmt() {
public String getTxnAmt() {
return txnAmt;
}
public void setTxnAmt(Long txnAmt) {
public void setTxnAmt(String txnAmt) {
this.txnAmt = txnAmt;
}
public Long getDscAmt() {
public String getDscAmt() {
return dscAmt;
}
public void setDscAmt(Long dscAmt) {
public void setDscAmt(String dscAmt) {
this.dscAmt = dscAmt;
}
......@@ -292,4 +296,21 @@ public class HlsEbankCmbTransqry {
public void setLastUpdatedBy(Long lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getQueryCategory() {
return queryCategory;
}
public void setQueryCategory(String queryCategory) {
this.queryCategory = queryCategory;
}
}
......@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject;
import com.chinapay.comm.Constants;
import com.chinapay.dto.HlsEbankCcbTransaction;
import com.chinapay.mapper.HlsEbankCcbTransactionMapper;
import com.chinapay.secss.LogUtil;
import com.chinapay.service.IHlsEbankCcbTransactionService;
import com.chinapay.util.StringUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
......@@ -18,16 +17,21 @@ import com.hand.app.cmb.util.SM2Util;
import com.hand.app.cmb.util.SignatureUtil;
import com.hand.app.cmb.util.Utils;
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.hap.core.IRequest;
import com.hand.hap.intergration.dto.HapInterfaceHeader;
import com.hand.hap.intergration.service.IHapInterfaceHeaderService;
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.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
......@@ -36,20 +40,23 @@ import java.util.stream.Collectors;
@Service
public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
static{
private static Properties pro = null;
static {
String path = Thread.currentThread().getContextClassLoader().getResource("").getPath().substring(1);
Properties pro = Utils.loadProp(path + "cmb.properties");
if (Objects.isNull(pro)){
pro = Utils.loadProp(path + "cmb.properties");
if (Objects.isNull(pro)) {
LoggerFactory.getLogger(HclcCmbPolyServiceImpl.class).error("配置文件初始化异常");
}
}
/*接口区分*/
public static final String getQrCode = "GET_QR_CODE";
public static final String queryQrState = "QUERY_QR_STATE";
public static final String closeOrder="CLOSE_ORDER";
public static final String closeOrder = "CLOSE_ORDER";
/*代扣交易状态*/
/*交易订单事务状态*/
public static final String tranSuccess = "SUCCESS";
public static final String transNew = "NEW";
public static final String transDeal = "DEAL";
......@@ -62,6 +69,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
public static final String orderDelete = "D";
public static final String orderCancel = "C";
public static final String orderPass = "P";
public static final String orderNo = "N";
@Autowired
......@@ -74,16 +82,18 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
private Ld037Mapper ld037Mapper;
@Autowired
private HlsEbankCmbTransqryMapper hlsEbankCmbTransqryMapper;
@Autowired
IHapInterfaceHeaderService headerService;
@Autowired
private DataSourceTransactionManager transactionManager;
private Logger logger = LoggerFactory.getLogger(getClass());
private static Properties pro = null;
@Override
public JSONObject getQrcode(IRequest iRequest, JSONObject params) {
JSONObject result = new JSONObject();
String resultType = "-1";
String errorCd = null;
HlsEbankCmbTransqry hlsEbankCmbTransqry = new HlsEbankCmbTransqry();
if (Objects.isNull(params.get("recamt_id"))) {
result.put(Constants.RESP_CODE, "E");
......@@ -111,21 +121,15 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
String dateString = formatter.format(new Date());
hlsEbankCcbTransaction.setTransactionNumber(dateString + String.format("%08d", hlsEbankCcbTransaction.getTransactionId()));
// Map<String, String> requestPublicParams = JSONObject.parseObject(params.toJSONString(), Map.class);
// 组装requestBody并加签
String signResult = getQrRequestParams(hlsEbankCcbTransaction, ld037);
if (Objects.isNull(signResult)) {
result.put(Constants.RESP_CODE, "E");
result.put(Constants.RESP_MSG, "收款码申请加签发生异常,请检查!");
return result;
}
hlsEbankCmbTransqry.setOrderId(hlsEbankCcbTransaction.getCmbOrderId());
hlsEbankCmbTransqry.setTxnAmt(Math.round(hlsEbankCcbTransaction.getAmount()*100));
Map<String, String> response = null;
try {
// 组装requestBody并加签
String signResult = getQrRequestParams(hlsEbankCcbTransaction, ld037);
if (Objects.isNull(signResult)) {
throw new Exception("加签发生异常");
}
ObjectMapper mapper = new ObjectMapper();
Map<String, String> signResultMap = mapper.readValue(signResult, Map.class);
long currentTimeMills = System.currentTimeMillis() / 1000;
......@@ -143,17 +147,17 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
// 组request头部Map
Map<String, String> apiHeader = new HashMap<>();
apiHeader.put("appid", pro.getProperty("cmb.appId"));
apiHeader.put("appid", pro.getProperty("cmb.appId"));
apiHeader.put("timestamp", "" + currentTimeMills);
apiHeader.put("apisign", apiSignString);
//初始化日志
HlsWsRequests hlsWsRequests = logInterfaceRequest(getQrCode, pro.getProperty("qrCodeapplyUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
HlsWsRequests hlsWsRequests = logInterfaceRequest(getQrCode, pro.getProperty("cmb.qrCodeapplyUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
logger.info("发送收款码申请请求,请求参数: {}", mapper.writeValueAsString(apiHeader));
try {
// 发送HTTP post请求
response = Utils.postForEntity( pro.getProperty("cmb.qrCodeapplyUrl"), signResult, apiHeader);
response = Utils.postForEntity(pro.getProperty("cmb.qrCodeapplyUrl"), signResult, apiHeader);
//处理接口日志
logger.info("收款码申请返回结果:" + mapper.writeValueAsString(response));
......@@ -168,24 +172,16 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
if (checkResult1) {
//获取返回码,返回码不为SUCCESS表示报文内的字段不符合规范
String returnCode = response.get("returnCode");
hlsEbankCmbTransqry.setReturnCode(returnCode);
if ("SUCCESS".equalsIgnoreCase(returnCode)) {
//响应码
String respCode = response.get("respCode");
hlsEbankCmbTransqry.setRespCode(respCode);
if ("SUCCESS".equalsIgnoreCase(respCode)) {
resultType = "1";
hlsEbankCmbTransqry.setCmbOrderId(response.get("cmbOrderId"));
hlsEbankCmbTransqry.setTxnTime(response.get("txnTime"));
} else {
resultType = "2";
hlsEbankCmbTransqry.setErrCode(response.get("errCode"));
hlsEbankCmbTransqry.setRespMsg(response.get("respMsg"));
}
} else {
resultType = "3";
hlsEbankCmbTransqry.setErrCode(response.get("errCode"));
hlsEbankCmbTransqry.setRespMsg(response.get("respMsg"));
}
if (!"1".equalsIgnoreCase(resultType)) {
......@@ -213,21 +209,19 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
hlsWsRequests.setResponsedDate(new Date());
//请求批次事务表状态更新失败处理
hlsEbankCcbTransaction.setReturnMsg(e.getMessage());
result.put(Constants.RESP_MSG, "发送请求异常:" + e.getMessage());
hlsEbankCcbTransaction.setReturnMsg("发送请求异常,请查看日志");
result.put(Constants.RESP_MSG, "发送请求异常,请查看日志!");
resultType = "5";
}
hlsWsRequestsMapper.updateByPrimaryKeySelective(hlsWsRequests);
hlsEbankCmbTransqryMapper.updateByPrimaryKey(hlsEbankCmbTransqry);
} catch (Exception e) {
e.printStackTrace();
logger.info("组装请求报文信息失败: {} ", e.getMessage());
//请求批次事务表状态更新失败处理
hlsEbankCcbTransaction.setReturnMsg("组装请求报文信息失败:" + e.getMessage());
result.put(Constants.RESP_MSG, "组装请求报文信息失败:" + e.getMessage());
hlsEbankCcbTransaction.setReturnMsg("组装请求报文信息失败,请查看日志");
result.put(Constants.RESP_MSG, "组装请求报文信息失败,请查看日志!");
errorCd = "MESSAGE_ERROR";
resultType = "5";
......@@ -255,17 +249,12 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
result.put(Constants.RESP_CODE, response.get("returnCode"));
result.put(Constants.RESP_MSG, "请求成功");
//测试环境处理,生产需要还原
result.put("qrcode", bizContent.getString("qrCode").replace("https://qr.95516.com/","http://payment-uat.cs.cmburl.cn/"));
result.put("cmborderid", bizContent.getString("cmbOrderId"));
result.put("qrCode", bizContent.getString("qrCode").replace("https://qr.95516.com/", "http://payment-uat.cs.cmburl.cn/"));
result.put("cmbOrderId", bizContent.getString("cmbOrderId"));
result.put("txnTime", bizContent.getString("txnTime"));
}
//接口返回成功,响应失败
else if ("2".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, response.get("errCode"));
result.put(Constants.RESP_MSG, response.get("respMsg"));
}
//接口返回失败
else if ("3".equalsIgnoreCase(type)) {
else if ("2".equalsIgnoreCase(type) || "3".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, response.get("errCode"));
result.put(Constants.RESP_MSG, response.get("respMsg"));
}
......@@ -292,34 +281,34 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
hlsEbankCcbTransaction.setQrCode(bizContent.getString("qrCode"));
hlsEbankCcbTransaction.setCmbOrderId(bizContent.getString("cmbOrderId"));
hlsEbankCcbTransaction.setTxnTime(bizContent.getString("txnTime"));
hlsEbankCcbTransaction.setOrderStatus("0000");
hlsEbankCcbTransaction.setOrderStatus(orderPass);
}
//接口返回成功,响应失败
else if ("2".equalsIgnoreCase(type)) {
hlsEbankCcbTransaction.setStatus(transFail);
hlsEbankCcbTransaction.setReturnCode(response.get("errCode"));
hlsEbankCcbTransaction.setReturnMsg(response.get("respMsg"));
hlsEbankCcbTransaction.setOrderStatus("0000");
hlsEbankCcbTransaction.setOrderStatus(orderFail);
}
//接口返回失败
else if ("3".equalsIgnoreCase(type)) {
hlsEbankCcbTransaction.setStatus(transFail);
hlsEbankCcbTransaction.setReturnCode(response.get("errCode"));
hlsEbankCcbTransaction.setReturnMsg(response.get("respMsg"));
hlsEbankCcbTransaction.setOrderStatus("0003");
hlsEbankCcbTransaction.setOrderStatus(orderFail);
}
//验签失败
else if ("4".equalsIgnoreCase(type)) {
hlsEbankCcbTransaction.setStatus(transFail);
hlsEbankCcbTransaction.setReturnCode("SIGN_ERROR");
hlsEbankCcbTransaction.setReturnMsg("接口请求验签失败");
hlsEbankCcbTransaction.setOrderStatus("0003");
hlsEbankCcbTransaction.setOrderStatus(orderFail);
}
//组装请求报文信息失败
else if ("5".equalsIgnoreCase(type)) {
hlsEbankCcbTransaction.setStatus(transFail);
hlsEbankCcbTransaction.setReturnCode("SEND_ERROR");
hlsEbankCcbTransaction.setOrderStatus("0003");
hlsEbankCcbTransaction.setOrderStatus(orderFail);
}
return hlsEbankCcbTransaction;
}
......@@ -358,7 +347,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
return hlsEbankCcbTransactionMapper.selectByPrimaryKey(ccbTransaction);
}
private String getQrRequestParams(HlsEbankCcbTransaction hlsEbankCcbTransaction,Ld037 ld037) {
private String getQrRequestParams(HlsEbankCcbTransaction hlsEbankCcbTransaction, Ld037 ld037) {
Map<String, String> requestPublicParams = new TreeMap<>();
String requestStr = null;
try {
......@@ -375,13 +364,13 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
// requestTransactionParams.put("termId", "00774411"); //终端号
requestTransactionParams.put("payValidTime", pro.getProperty("cmb.payValidTime")); //支付有效时间,默认15分钟
requestTransactionParams.put("notifyUrl", pro.getProperty("cmb.notifyUrl")); //交易通知地址(必传)
requestTransactionParams.put("mchReserved", ld037.getId().toString()); //保留字段
requestTransactionParams.put("mchReserved", "{\"recamt_id\":" + ld037.getId() + "}"); //保留字段
BigDecimal a1 = new BigDecimal(Double.toString(hlsEbankCcbTransaction.getAmount()));
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", "聚合支付测试"); //商户号(必传)
//商户保留域
JSONObject mchReserved = new JSONObject();
......@@ -396,7 +385,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//对待加签内容进行排序拼接
String signContent = SignatureUtil.getSignContent(requestPublicParams);
//加签
requestPublicParams.put("sign", SM2Util.sm2Sign(signContent, pro.getProperty("cmb.privateKey")));
requestPublicParams.put("sign", SM2Util.sm2Sign(signContent, pro.getProperty("cmb.privateKey")));
requestStr = mapper.writeValueAsString(requestPublicParams);
logger.info("收款码申请加签后的报文内容:" + requestStr);
......@@ -409,65 +398,11 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
}
}
private Boolean checkSign(String string) {
System.out.println("要验签的报文内容:" + string);
try {
//验签
ObjectMapper objectMapper = new ObjectMapper();
Map<String, String> responseBodyMap = objectMapper.readValue(string, Map.class);
String sign = responseBodyMap.remove("sign");
String contentStr = SignatureUtil.getSignContent(responseBodyMap);
boolean result = SM2Util.sm2Check(contentStr, sign, pro.getProperty("cmb.publicKey"));
if (result) {
System.out.println("报文验签成功!");
} else {
System.out.println("报文验签失败!");
}
return result;
} catch (Exception e) {
System.out.println("验签发生异常!");
e.printStackTrace();
return false;
}
}
public HlsWsRequests logInterfaceRequest(String functionName, String url, String request, Long pkValue) {
HlsWsRequests hlsWsRequests = new HlsWsRequests();
hlsWsRequests.setRequestDate(new Date());
hlsWsRequests.setRequestWsdlUrl(url);
hlsWsRequests.setFunctionName(functionName);
String tableName = getTableName(functionName);
hlsWsRequests.setTableName(tableName);
hlsWsRequests.setStatusCode("1");
hlsWsRequests.setStatusDate(new Date());
hlsWsRequests.setPkValue(pkValue);
hlsWsRequests.setRequestClob(request);
hlsWsRequestsMapper.insertSelective(hlsWsRequests);
return hlsWsRequests;
}
private String getTableName(String functionName) {
String tableName = "";
if ("GET_QR_CODE".equalsIgnoreCase(functionName)) {
tableName = "HLS_EBANK_CCB_TRANSACTION";
} else if ("QUERY_PAY_RESULT".equalsIgnoreCase(functionName)) {
tableName = "HLS_EBANK_CMB_QUERY";
}
return tableName;
}
@Override
public JSONObject queryOrderStatus(IRequest iRequest, JSONObject params){
public JSONObject queryOrderStatus(IRequest iRequest, JSONObject params) {
//返回结果标志
String resultType = null;
JSONObject result = new JSONObject();
HlsEbankCmbTransqry hlsEbankCmbTransqry = new HlsEbankCmbTransqry();
//去ld037中查找对应的记录的receiptcfmstatus,
if (Objects.isNull(params.get("recamt_id"))) {
result.put(Constants.RESP_CODE, "E");
......@@ -484,35 +419,56 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//与查询二维码有区别,查询二维码时订单并未创建,但查询订单状态时,订单记录已经在数据库中有记录,
// 所以只需要通过recamt_id在ld037表中查到对应的订单记录,
// 然后通过ld037表中的transaction_id找到对应的hlsEbankCcbTransaction对象
HlsEbankCcbTransaction hlsEbankCcbTransaction = hlsEbankCcbTransactionMapper.selectByPrimaryKey(ld037.getTransactionId());
// HlsEbankCcbTransaction hlsEbankCcbTransaction = createTransaction(ld037)
String signResult = getOrderQueryParameter(hlsEbankCcbTransaction);
if (hlsEbankCcbTransaction.getOrderStatus().equals(tranSuccess)){
result.put(Constants.RESP_CODE, hlsEbankCcbTransaction.getReturnCode());
result.put(Constants.RESP_MSG, hlsEbankCcbTransaction.getReturnMsg());
HlsEbankCcbTransaction hlsEbankCcbTransaction = new HlsEbankCcbTransaction();
hlsEbankCcbTransaction.setTransactionId(ld037.getTransactionId());
hlsEbankCcbTransaction = hlsEbankCcbTransactionMapper.selectByPrimaryKey(hlsEbankCcbTransaction);
if (Objects.isNull(hlsEbankCcbTransaction) || "CMB".equalsIgnoreCase(hlsEbankCcbTransaction.getBankType())) {
result.put(Constants.RESP_CODE, "S");
result.put(Constants.RESP_MSG, "订单不存在");
//给到前端订单的状态
result.put("tradeState", orderNo);
return result;
}
if (!transDeal.equalsIgnoreCase(hlsEbankCcbTransaction.getStatus())) {
result.put(Constants.RESP_CODE, "S");
result.put(Constants.RESP_MSG, "查询成功");
//给到前端订单的状态
result.put("tradeState",hlsEbankCcbTransaction.getOrderStatus());
result.put("tradeState", hlsEbankCcbTransaction.getOrderStatus());
return result;
}
hlsEbankCmbTransqry.setOrderId(hlsEbankCcbTransaction.getCmbOrderId());
hlsEbankCmbTransqry.setTxnAmt(Math.round(hlsEbankCcbTransaction.getAmount()*100));
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
// 事务隔离级别:开启新事务
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
//对于每次请求都开启一个事物
TransactionStatus transactionStatus = transactionManager.getTransaction(def);
Map<String,String> responseMap = null;
ObjectMapper mapper =null;
HlsWsRequests hlsWsRequests = null;
try{
mapper = new ObjectMapper();
Map<String,String> signResultMap = mapper.readValue(signResult, Map.class);
//创建订单查询记录
HlsEbankCmbTransqry hlsEbankCmbTransqry = createTransqry(hlsEbankCcbTransaction.getTransactionId(), "GET");
long currentTimeMills = System.currentTimeMillis() / 1000;
//生成单据编号 日期+id
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String dateString = formatter.format(new Date());
hlsEbankCmbTransqry.setTransqryNumber(dateString + String.format("%08d", hlsEbankCcbTransaction.getTransactionId()));
Map<String, String> responseMap = null;
try {
String signResult = getOrderQueryParameter(hlsEbankCcbTransaction);
if (Objects.isNull(signResult)) {
throw new Exception("加签发生异常");
}
ObjectMapper mapper = new ObjectMapper();
Map<String, String> signResultMap = mapper.readValue(signResult, Map.class);
// 组apiSign加密Map
Map<String,String> apiSign = new TreeMap<>();
Map<String, String> apiSign = new TreeMap<>();
apiSign.put("appid", pro.getProperty("cmb.appId"));
apiSign.put("secret", pro.getProperty("cmb.appSecret"));
apiSign.put("sign", signResultMap.get("sign"));
long currentTimeMills = System.currentTimeMillis() / 1000;
apiSign.put("timestamp", "" + currentTimeMills);
// MD5加密
......@@ -525,92 +481,208 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
apiHeader.put("timestamp", "" + currentTimeMills);
apiHeader.put("apisign", apiSignString);
//初始化日志
HlsWsRequests hlsWsRequests = logInterfaceRequest(queryQrState, pro.getProperty("cmb.orderQueryUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
try {
//发送http请求
responseMap = Utils.postForEntity(pro.getProperty("cmb.orderQueryUrl"), signResult, apiHeader);
//处理接口日志
logger.info("收款码申请返回结果:" + mapper.writeValueAsString(responseMap));
hlsWsRequests.setResponseClob(mapper.writeValueAsString(responseMap));
hlsWsRequests.setReturnStatus("S");
//处理响应报文
Boolean checkResponse = checkSign(mapper.writeValueAsString(responseMap));
hlsWsRequests = logInterfaceRequest(queryQrState, pro.getProperty("cmb.orderQueryUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
//发送http请求
responseMap = Utils.postForEntity(queryQrState,signResult,apiHeader);
if( null == responseMap){
resultType="3";
logger.info("响应的内容为空");
return result;
//数据验签成功
if (checkResponse) {
//获取返回码,返回码不为SUCCESS表示报文内的字段不符合规范
String returnCode = responseMap.get("returnCode");
if ("SUCCESS".equalsIgnoreCase(returnCode)) {
//响应码
String respCode = responseMap.get("respCode");
if ("SUCCESS".equalsIgnoreCase(respCode)) {
//成功拿到订单状态请求的响应
hlsEbankCmbTransqry = finishTransaction(responseMap, hlsEbankCcbTransaction, hlsEbankCmbTransqry);
resultType = "7";
} else {
//ORDERID_INVALID 停止发起查询,调起关单
if ("ORDERID_INVALID".equalsIgnoreCase(responseMap.get("errCode"))) {
JSONObject closeResult = closeOrder(iRequest, params);
//订单关闭成功
if (tranSuccess.equalsIgnoreCase(closeResult.getString("respCode"))) {
resultType = "1";
}
//订单关闭失败
else {
resultType = "6";
}
} else {
//请求成功,但是响应结果为失败,传给前端失败原因就行
resultType = "2";
}
}
} else {
//返回码都失败
resultType = "3";
}
}
//数据验签失败
else {
//直接返回前端验签失败信息,重发或者直接告诉前端发送失败
resultType = "4";
}
} catch (Exception e) {
e.printStackTrace();
logger.info("发送请求异常: {} ", e.getMessage());
//处理接口日志
hlsWsRequests.setReturnStatus("E");
//请求批次事务表状态更新失败处理
hlsEbankCmbTransqry.setRespMsg("发送请求异常,请查看日志");
result.put(Constants.RESP_MSG, "发送请求异常,请查看日志!");
resultType = "5";
}
hlsWsRequests.setResponseClob(mapper.writeValueAsString(responseMap));
hlsWsRequests.setReturnStatus("S");
//更新log日志表
hlsWsRequests.setResponsedDate(new Date());
//处理响应报文
Boolean checkResponse = null;
try {
checkResponse = checkSign(mapper.writeValueAsString(responseMap));
} catch (JsonProcessingException e) {
resultType = "4";
e.printStackTrace();
hlsWsRequestsMapper.updateByPrimaryKeySelective(hlsWsRequests);
} catch (Exception e) {
e.printStackTrace();
logger.info("组装请求报文信息失败: {} ", e.getMessage());
//请求查询订单状态失败处理
hlsEbankCmbTransqry.setRespMsg("组装请求报文信息失败,请查看日志");
result.put(Constants.RESP_MSG, "组装请求报文信息失败,请查看日志!");
resultType = "5";
}
//设置查询失败结果信息
hlsEbankCmbTransqry = setEbankTransqry(hlsEbankCmbTransqry, responseMap, resultType);
hlsEbankCmbTransqryMapper.updateByPrimaryKeySelective(hlsEbankCmbTransqry);
//状态刷新
transactionStatus.flush();
//事务提交
transactionManager.commit(transactionStatus);
result = putResultQR(result, responseMap, resultType);
if ("7".equalsIgnoreCase(resultType)) {
JSONObject ld037Param = new JSONObject();
ld037Param.put("transaction_id", hlsEbankCcbTransaction.getTransactionId());
postWriteLd037(ld037Param);
}
return result;
}
//生成招行扫码交易业务批次数据
private HlsEbankCmbTransqry createTransqry(Long transactionId, String queryCategory) {
HlsEbankCmbTransqry cmbTransqry = new HlsEbankCmbTransqry();
cmbTransqry.setMerId(pro.getProperty("cmb.mer.id"));
cmbTransqry.setVersion(pro.getProperty("cmb.version"));
cmbTransqry.setTransactionId(transactionId);
cmbTransqry.setStatus(transNew);
cmbTransqry.setCreatedBy(1L);
cmbTransqry.setCreationDate(new Date());
cmbTransqry.setLastUpdatedBy(1L);
cmbTransqry.setQueryCategory(queryCategory);
hlsEbankCmbTransqryMapper.insert(cmbTransqry);
return hlsEbankCmbTransqryMapper.selectByPrimaryKey(cmbTransqry);
}
private String postWriteLd037(JSONObject params) {
String sysName = "HCL_UPLOAD_FILE";
String apiName = "writeOffLd037";
try {
//初始化接口信息
HapInterfaceHeader headerAndLineDTO = headerService.getHeaderAndLine(sysName, apiName);
if (headerAndLineDTO == null) {
logger.info("headerAndLineDTO is null, apiName:{}, sysName:{}", apiName, sysName);
return "N";
}
//数据验签成功 if (checkResponse) {
//获取返回码,返回码不为SUCCESS表示报文内的字段不符合规范
String returnCode = responseMap.get("returnCode");
hlsEbankCmbTransqry.setReturnCode(returnCode);
if ("SUCCESS".equalsIgnoreCase(returnCode)) {
//响应码
String respCode = responseMap.get("returnCode");
if ("SUCCESS".equalsIgnoreCase(respCode)) {
//成功拿到订单状态请求的响应
hlsEbankCmbTransqry.setCmbOrderId(responseMap.get("cmbOrderId"));
hlsEbankCmbTransqry.setTxnTime(responseMap.get("txnTime"));
hlsEbankCmbTransqry.setPayType(responseMap.get("payType"));
hlsEbankCmbTransqry.setPayBank(responseMap.get("payBank"));
hlsEbankCmbTransqry.setTradeState(responseMap.get("tradeState"));
hlsEbankCmbTransqry.setEndDate(responseMap.get("endDate"));
hlsEbankCmbTransqry.setEndTime(responseMap.get("endTime"));
resultType = "1";
} else {
if ("SYSTERM_ERROR".equalsIgnoreCase(responseMap.get("errcode"))){
hlsEbankCmbTransqry.setReturnCode(respCode);
resultType = "6";
}else{
//请求成功,但是响应结果为失败,传给前端失败原因就行
hlsEbankCmbTransqry.setErrCode(responseMap.get("errCode"));
hlsEbankCmbTransqry.setRespMsg(responseMap.get("respMsg"));
resultType = "2";
}
}
String url = headerAndLineDTO.getDomainUrl() + headerAndLineDTO.getIftUrl();
Map<String, String> headInfo = new HashMap<String, String>();
headInfo.put("Content-Type", "application/x-www-form-urlencoded");
JSONObject requestData = new JSONObject();
requestData.put("requestData", params.toString());
//发送http请求
SignHclcUtils signHclcUtils1 = new SignHclcUtils();
String stringResult = signHclcUtils1.postString(url, requestData, headInfo, signHclcUtils1.APPLICATION_FORM_URLENCODED);
//解析返回结果
JSONObject jsonResult = JSONObject.parseObject(stringResult);
if ("S".equalsIgnoreCase(jsonResult.getString("respCode"))) {
return "Y";
} else {
//返回码都失败
hlsEbankCmbTransqry.setErrCode(responseMap.get("errCode"));
hlsEbankCmbTransqry.setRespMsg(responseMap.get("respMsg"));
resultType = "3";
return "N";
}
} catch (Exception e) {
e.printStackTrace();
return "N";
}
}
if (!"1".equalsIgnoreCase(resultType)) {
//更新现金事务表ld037失败处理
updateLd037Fail(ld037, responseMap.get("errCode"));
//订单完成通用接口
private HlsEbankCmbTransqry finishTransaction(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"))) {
hlsEbankCcbTransaction.setStatus(tranSuccess);
hlsEbankCcbTransaction.setSuccessDate(new Date());
}
//数据验签失败
else {
//更新现金事务表ld037失败处理
updateLd037Fail(ld037, "SIGN_ERROR");
//直接返回前端验签失败信息,重发或者直接告诉前端发送失败
resultType = "4";
if ("S".equalsIgnoreCase(bizContent.getString("tradeState"))) {
hlsEbankCcbTransaction.setSuccessAmount(hlsEbankCcbTransaction.getAmount());
hlsEbankCcbTransaction.setSuccessCount(hlsEbankCcbTransaction.getCount());
}
}catch(Exception e){
hlsWsRequests.setReturnStatus("E");
hlsWsRequests.setResponsedDate(new Date());
}
hlsEbankCmbTransqryMapper.updateByPrimaryKey(hlsEbankCmbTransqry);
hlsWsRequestsMapper.updateByPrimaryKeySelective(hlsWsRequests);
hlsEbankCcbTransaction = setEbankTransactionQR(hlsEbankCcbTransaction, responseMap, resultType);
hlsEbankCcbTransaction.setOrderStatus(bizContent.getString("tradeState"));
hlsEbankCcbTransactionMapper.updateByPrimaryKeySelective(hlsEbankCcbTransaction);
result = putResult(result, responseMap, resultType);
return result;
//更新查询表数据
hlsEbankCmbTransqry.setReturnCode(responseMap.get("respCode"));
hlsEbankCmbTransqry.setOrderId(bizContent.getString("orderId"));
hlsEbankCmbTransqry.setCmbOrderId(bizContent.getString("cmbOrderId"));
hlsEbankCmbTransqry.setRespCode(responseMap.get("respCode"));
hlsEbankCmbTransqry.setTxnAmt(bizContent.getString("txnAmt"));
hlsEbankCmbTransqry.setDscAmt(bizContent.getString("dscAmt"));
hlsEbankCmbTransqry.setCurrencyCode(bizContent.getString("currencyCode"));
hlsEbankCmbTransqry.setPayType(bizContent.getString("payType"));
hlsEbankCmbTransqry.setOpenId(bizContent.getString("openId"));
hlsEbankCmbTransqry.setPayBank(bizContent.getString("payBank"));
hlsEbankCmbTransqry.setThirdOrderId(bizContent.getString("thirdOrderId"));
hlsEbankCmbTransqry.setBuyerLogonId(bizContent.getString("buyerLogonId"));
hlsEbankCmbTransqry.setTradeState(bizContent.getString("tradeState"));
hlsEbankCmbTransqry.setTxnTime(bizContent.getString("txnTime"));
hlsEbankCmbTransqry.setEndDate(bizContent.getString("endDate"));
hlsEbankCmbTransqry.setEndTime(bizContent.getString("endTime"));
hlsEbankCmbTransqry.setStatus("0000");
return hlsEbankCmbTransqry;
}
/**
* 封装请求参数,其中包含商户订单号,作为招行收到请求定位到对应订单的条件
* 封装请求参数,其中包含商户订单号,作为招行收到请求定位到对应订单的条件
*
* @param hlsEbankCcbTransaction
* @return
*/
private static String getOrderQueryParameter(HlsEbankCcbTransaction hlsEbankCcbTransaction){
private String getOrderQueryParameter(HlsEbankCcbTransaction hlsEbankCcbTransaction) {
Map<String, String> requestPublicParams = new TreeMap<>();
String requestStr = null;
try {
......@@ -622,94 +694,83 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
Map<String, String> requestTransactionParams = new HashMap<>();
requestTransactionParams.put("merId", hlsEbankCcbTransaction.getMerId()); //商户号(必传)
requestTransactionParams.put("orderId", hlsEbankCcbTransaction.getTransactionNumber()); //商户订单号(必传)
requestTransactionParams.put("cmbOrderId", hlsEbankCcbTransaction.getCmbOrderId()); //商户订单号(必传)
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);
String signContent = SignatureUtil.getSignContent(requestPublicParams);
//加签
requestPublicParams.put("sign", SM2Util.sm2Sign(signContent, pro.getProperty("cmb.privateKey")));
requestStr = mapper.writeValueAsString(requestPublicParams);
System.out.println("加签后的报文内容:" + requestStr);
return requestStr;
logger.info("加签后的报文内容:" + requestStr);
}catch (Exception e){
System.out.println("加签发生异常!");
} catch (Exception e) {
logger.info("加签发生异常!" + e.getMessage());
e.printStackTrace();
return requestStr;
}
return requestStr;
}
/**
* 封装交易表批次信息表
* @param hlsEbankCcbTransaction
* 封装交易表批次信息表
*
* @param hlsEbankCmbTransqry
* @param response
* @param type
* @return
*/
private HlsEbankCcbTransaction setEbankTransactionQR(HlsEbankCcbTransaction hlsEbankCcbTransaction, Map<String, String> response, String type) {
//
//接口请求成功
if ("1".equalsIgnoreCase(type)) {
if (response.get("tradeState").equalsIgnoreCase("P")){
hlsEbankCcbTransaction.setStatus(transDeal);
hlsEbankCcbTransaction.setOrderStatus("P");
}
else if (response.get("tradeState").equalsIgnoreCase("S")){
hlsEbankCcbTransaction.setStatus(tranSuccess);
hlsEbankCcbTransaction.setOrderStatus("S");
}
else if (response.get("tradeState").equalsIgnoreCase("C")){
hlsEbankCcbTransaction.setStatus(tranSuccess);
hlsEbankCcbTransaction.setOrderStatus("C");
}
else if (response.get("tradeState").equalsIgnoreCase("F")){
hlsEbankCcbTransaction.setStatus(tranSuccess);
hlsEbankCcbTransaction.setOrderStatus("F");
}
}
private HlsEbankCmbTransqry setEbankTransqry(HlsEbankCmbTransqry hlsEbankCmbTransqry, Map<String, String> response, String type) {
// C - 订单已关闭
// D - 交易已撤销
// P - 交易在进行
// F - 交易失败
// S - 交易成功
// R - 转入退款
//接口返回成功,响应失败
else if ("2".equalsIgnoreCase(type)) {
hlsEbankCcbTransaction.setReturnCode(response.get("errCode"));
hlsEbankCcbTransaction.setReturnMsg(response.get("respMsg"));
hlsEbankCcbTransaction.setOrderStatus("0000");
if ("1".equalsIgnoreCase(type) || "2".equalsIgnoreCase(type) || "6".equalsIgnoreCase(type)) {
hlsEbankCmbTransqry.setReturnCode(response.get("returnCode"));
hlsEbankCmbTransqry.setRespCode(response.get("respCode"));
hlsEbankCmbTransqry.setErrCode(response.get("errCode"));
hlsEbankCmbTransqry.setRespMsg(response.get("respMsg"));
hlsEbankCmbTransqry.setErrDescription(response.get("errDescription"));
hlsEbankCmbTransqry.setStatus("0000");
}
//接口返回失败
else if ("3".equalsIgnoreCase(type)) {
hlsEbankCcbTransaction.setReturnCode(response.get("errCode"));
hlsEbankCcbTransaction.setReturnMsg(response.get("respMsg"));
hlsEbankCcbTransaction.setOrderStatus("0003");
hlsEbankCmbTransqry.setReturnCode(response.get("returnCode"));
hlsEbankCmbTransqry.setErrCode(response.get("errCode"));
hlsEbankCmbTransqry.setRespMsg(response.get("respMsg"));
hlsEbankCmbTransqry.setStatus("0000");
}
/* //验签失败
//验签失败
else if ("4".equalsIgnoreCase(type)) {
hlsEbankCcbTransaction.setReturnCode("SIGN_ERROR");
hlsEbankCcbTransaction.setReturnMsg("接口请求验签失败");
hlsEbankCcbTransaction.setOrderStatus("0003");
hlsEbankCmbTransqry.setReturnCode(transFail);
hlsEbankCmbTransqry.setErrCode("SIGN_ERROR");
hlsEbankCmbTransqry.setRespMsg("接口请求验签失败");
hlsEbankCmbTransqry.setStatus("0003");
}
//组装请求报文信息失败
else if ("5".equalsIgnoreCase(type)) {
hlsEbankCcbTransaction.setReturnCode("SEND_ERROR");
hlsEbankCcbTransaction.setOrderStatus("0003");
}*/
//招行服务器出错
/*else if ("6".equalsIgnoreCase(type)){
hlsEbankCcbTransaction.setReturnCode("CMB_SERVER_ERROR");
hlsEbankCcbTransaction.setOrderStatus("0003");
}*/
hlsEbankCmbTransqry.setReturnCode(transFail);
hlsEbankCmbTransqry.setErrCode("SEND_ERROR");
hlsEbankCmbTransqry.setStatus("0003");
}
return hlsEbankCcbTransaction;
return hlsEbankCmbTransqry;
}
/**
* 封装给前端的返回结果
* 封装给前端的返回结果
*
* @param result
* @param response
* @param type
......@@ -718,37 +779,29 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
private JSONObject putResultQR(JSONObject result, Map<String, String> response, String type) {
//接口请求成功
if ("1".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, response.get("returnCode"));
result.put(Constants.RESP_MSG, "请求成功");
result.put("orderId", response.get("orderId"));
result.put("cmbOrderId", response.get("cmbOrderId"));
result.put("tradeState", response.get("tradeState"));
result.put("txnTime", response.get("txnTime"));
result.put(Constants.RESP_CODE, tranSuccess);
result.put(Constants.RESP_MSG, "订单已关闭");
//给到前端订单的状态
result.put("tradeState", orderCancel);
}
//接口返回成功,响应失败
else if ("2".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, response.get("errCode"));
result.put(Constants.RESP_MSG, response.get("respMsg"));
}
//接口返回失败
else if ("3".equalsIgnoreCase(type)) {
else if ("2".equalsIgnoreCase(type) || "3".equalsIgnoreCase(type) || "6".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, response.get("errCode"));
result.put(Constants.RESP_MSG, response.get("respMsg"));
}
//验签失败
else if ("4".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, transFail);
result.put(Constants.RESP_MSG, "验签失败,请检查!");
result.put(Constants.RESP_MSG, "验签失败!");
}
//组装请求报文信息失败
else if ("5".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, transFail);
}
else if ("6".equalsIgnoreCase(type)){
result.put(Constants.RESP_CODE, response.get("errCode"));
result.put(Constants.RESP_MSG, "服务器出错,请重新查询!");
} else if ("7".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, tranSuccess);
result.put(Constants.RESP_MSG, "查询成功");
//给到前端订单的状态
result.put("tradeState", JSONObject.parseObject(response.get("biz_content")).getString("tradeState"));
}
return result;
}
......@@ -782,7 +835,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//对待加签内容进行排序拼接
String contentStr = SignatureUtil.getSignContent(resultMap);
//验证签名-使用招行公钥进行验签
boolean flag = SM2Util.sm2Check(contentStr,sign, pro.getProperty("cmb.publicKey"));
boolean flag = SM2Util.sm2Check(contentStr, sign, pro.getProperty("cmb.publicKey"));
if (!flag) {
//验签失败
System.out.println("验签失败");
......@@ -799,7 +852,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
/*对请求结果进行保存*/
HlsEbankCcbTransaction hlsEbankCcbTransaction = hlsEbankCcbTransactionMapper.selectByPrimaryKey(ld037.getTransactionId());
hlsEbankCcbTransaction.setStatus(tranSuccess);
hlsEbankCcbTransaction.setOrderStatus("S");
hlsEbankCcbTransaction.setOrderStatus(orderSuccess);
hlsEbankCcbTransactionMapper.updateByPrimaryKeySelective(hlsEbankCcbTransaction);
hlsWsRequestsMapper.updateByPrimaryKey(logInterfaceRequest(queryQrState, pro.getProperty("cmb.server"), new ObjectMapper().writeValueAsString(respData), hlsEbankCcbTransaction.getTransactionId()));
respData.put("respCode", "SUCCESS");//业务错误码,成功为SUCCESS,失败为FAIL
......@@ -823,7 +876,6 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
@Override
public JSONObject closeOrder(IRequest iRequest, JSONObject params) {
JSONObject result = new JSONObject();
HlsEbankCmbTransqry hlsEbankCmbTransqry = new HlsEbankCmbTransqry();
if (Objects.isNull(params.get("recamt_id"))) {
result.put(Constants.RESP_CODE, "E");
result.put("respMsg", "请求必须参数recamt_id缺失,请检查!");
......@@ -839,23 +891,23 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
/**
* 支付成功的订单不允许关单,需要修改返回代码
*/
if ("SUCCESS".equalsIgnoreCase(hlsEbankCcbTransaction.getStatus())){
if ("SUCCESS".equalsIgnoreCase(hlsEbankCcbTransaction.getStatus())) {
result.put(Constants.RESP_CODE, "E");
result.put("respMsg", "订单已经支付成功!");
return result;
}
//开始封装请求部分
String signResult = getOrderQueryParameter(hlsEbankCcbTransaction);
String signResult = getOrderCloseParameter(hlsEbankCcbTransaction);
ObjectMapper mapper = new ObjectMapper();
Map<String, String> apiHeader = null;
try {
Map<String,String> signResultMap = mapper.readValue(signResult, Map.class);
Map<String, String> signResultMap = mapper.readValue(signResult, Map.class);
long currentTimeMills = System.currentTimeMillis() / 1000;
// 组apiSign加密Map
Map<String,String> apiSign = new TreeMap<>();
Map<String, String> apiSign = new TreeMap<>();
apiSign.put("appid", pro.getProperty("cmb.appId"));
apiSign.put("secret", pro.getProperty("cmb.privateKey"));
apiSign.put("sign", signResultMap.get("sign"));
......@@ -871,74 +923,61 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
apiHeader.put("timestamp", "" + currentTimeMills);
apiHeader.put("apisign", apiSignString);
hlsEbankCmbTransqry.setOrderId(hlsEbankCcbTransaction.getCmbOrderId());
hlsEbankCmbTransqry.setTxnAmt(Math.round(hlsEbankCcbTransaction.getAmount()*100));
} catch (IOException e) {
/// resultType = "5";
/// resultType = "5";
e.printStackTrace();
}
HlsWsRequests hlsWsRequests = null;
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);
Map<String, String> responseMap = Utils.postForEntity(pro.getProperty("cmb.closeUrl"), signResult, apiHeader);
//处理响应报文
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");
hlsEbankCmbTransqry.setReturnCode(returnCode);
if ("SUCCESS".equalsIgnoreCase(returnCode)) {
//响应码
String respCode = responseMap.get("respCode");
hlsEbankCmbTransqry.setRespCode(respCode);
hlsEbankCmbTransqry.setOrderId(responseMap.get("origOrderId"));
if ("ORDER_PAID".equalsIgnoreCase(respCode)){
if ("ORDER_PAID".equalsIgnoreCase(respCode)) {
//需要调用退款接口
result.put(Constants.RESP_CODE, "E");
result.put("respMsg", "需要调用退款接口!");
return result;
}
else if ("SUCCESS".equalsIgnoreCase(respCode)) {
} else if ("SUCCESS".equalsIgnoreCase(respCode)) {
//订单关闭成功
hlsEbankCmbTransqry.setTradeState(responseMap.get("closeState"));
hlsEbankCmbTransqry.setTxnTime(responseMap.get("txnTime"));
if ("C".equalsIgnoreCase(responseMap.get("closeState"))){
if ("C".equalsIgnoreCase(responseMap.get("closeState"))) {
hlsEbankCcbTransaction.setStatus(transClose);
hlsEbankCcbTransaction.setOrderStatus("C");
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("cmborderid", responseMap.get("origOrderId"));
result.put("closeState", responseMap.get("closeState"));
result.put("txnTime", responseMap.get("txnTime"));
}
//关单失败处理
else{
else {
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("cmborderid", responseMap.get("origOrderId"));
result.put("closeState", responseMap.get("closeState"));
result.put("txnTime", responseMap.get("txnTime"));
}
} else if ("SYSTERM_ERROR".equalsIgnoreCase(respCode)){
} else if ("SYSTERM_ERROR".equalsIgnoreCase(respCode)) {
//请求成功,但是响应结果为失败,传给前端失败原因就行
result.put(Constants.RESP_CODE, "E");
result.put("respMsg", "需要重新调用查询接口!");
}
else if ("FAIL".equalsIgnoreCase(respCode)){
hlsEbankCmbTransqry.setErrCode(responseMap.get("errCode"));
hlsEbankCmbTransqry.setRespMsg(responseMap.get("respMsg"));
} else if ("FAIL".equalsIgnoreCase(respCode)) {
result.put("errCode", responseMap.get("errCode"));
result.put("respMsg", responseMap.get("respMsg"));
}
} else {
//返回码都失败
hlsEbankCmbTransqry.setErrCode(responseMap.get("errCode"));
hlsEbankCmbTransqry.setRespMsg(responseMap.get("respMsg"));
result.put("errCode", responseMap.get("errCode"));
result.put("respMsg", responseMap.get("respMsg"));
}
......@@ -950,12 +989,48 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
hlsWsRequests.setResponsedDate(new Date());
e.printStackTrace();
}
hlsEbankCmbTransqryMapper.updateByPrimaryKey(hlsEbankCmbTransqry);
hlsWsRequestsMapper.updateByPrimaryKey(hlsWsRequests);
hlsEbankCcbTransactionMapper.updateByPrimaryKey(hlsEbankCcbTransaction);
return result;
}
private String getOrderCloseParameter(HlsEbankCcbTransaction hlsEbankCcbTransaction) {
Map<String, String> requestPublicParams = new TreeMap<>();
String requestStr = null;
try {
//公共请求参数
requestPublicParams.put("version", pro.getProperty("cmb.version")); //版本号,固定为0.0.1(必传字段)
requestPublicParams.put("encoding", pro.getProperty("cmb.encoding")); //编码方式,固定为UTF-8(必传)
requestPublicParams.put("signMethod", pro.getProperty("cmb.signMethod")); //签名方法,固定为02,表示签名方式为国密(必传)
//业务要素
Map<String, String> requestTransactionParams = new HashMap<>();
requestTransactionParams.put("merId", hlsEbankCcbTransaction.getMerId()); //商户号(必传)
requestTransactionParams.put("orderId", 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));
//对待加签内容进行排序拼接
String signContent = SignatureUtil.getSignContent(requestPublicParams);
//加签
requestPublicParams.put("sign", SM2Util.sm2Sign(signContent, pro.getProperty("cmb.privateKey")));
requestStr = mapper.writeValueAsString(requestPublicParams);
System.out.println("加签后的报文内容:" + requestStr);
return requestStr;
} catch (Exception e) {
System.out.println("加签发生异常!");
e.printStackTrace();
return requestStr;
}
}
private Map<String, String> str2Map(String str) {
Map<String, String> result = new HashMap<>();
String[] results = str.split("&");
......@@ -970,4 +1045,58 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
}
return result;
}
private Boolean checkSign(String string) {
System.out.println("要验签的报文内容:" + string);
try {
//验签
ObjectMapper objectMapper = new ObjectMapper();
Map<String, String> responseBodyMap = objectMapper.readValue(string, Map.class);
String sign = responseBodyMap.remove("sign");
String contentStr = SignatureUtil.getSignContent(responseBodyMap);
boolean result = SM2Util.sm2Check(contentStr, sign, pro.getProperty("cmb.publicKey"));
if (result) {
System.out.println("报文验签成功!");
} else {
System.out.println("报文验签失败!");
}
return result;
} catch (Exception e) {
System.out.println("验签发生异常!");
e.printStackTrace();
return false;
}
}
public HlsWsRequests logInterfaceRequest(String functionName, String url, String request, Long pkValue) {
HlsWsRequests hlsWsRequests = new HlsWsRequests();
hlsWsRequests.setRequestDate(new Date());
hlsWsRequests.setRequestWsdlUrl(url);
hlsWsRequests.setFunctionName(functionName);
String tableName = getTableName(functionName);
hlsWsRequests.setTableName(tableName);
hlsWsRequests.setStatusCode("1");
hlsWsRequests.setStatusDate(new Date());
hlsWsRequests.setPkValue(pkValue);
hlsWsRequests.setRequestClob(request);
hlsWsRequestsMapper.insertSelective(hlsWsRequests);
return hlsWsRequests;
}
private String getTableName(String functionName) {
String tableName = "";
if ("GET_QR_CODE".equalsIgnoreCase(functionName)) {
tableName = "HLS_EBANK_CCB_TRANSACTION";
} else if ("QUERY_PAY_RESULT".equalsIgnoreCase(functionName)) {
tableName = "HLS_EBANK_CMB_QUERY";
}
return tableName;
}
}
......@@ -4,9 +4,9 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hand.app.cmb.mapper.HlsEbankCmbTransqryMapper">
<resultMap id="baseMap" type="com.hand.app.cmb.dto.HlsEbankCmbTransqry">
<result column="TRANSQRY_ID" property="transqryId" jdbcType="NUMBER"/>
<result column="TRANSQRY_ID" property="transqryId" jdbcType="DECIMAL"/>
<result column="TRANSQRY_NUMBER" property="transqryNumber" jdbcType="VARCHAR"/>
<result column="TRANSACTION_ID" property="transactionId" jdbcType="NUMBER"/>
<result column="TRANSACTION_ID" property="transactionId" jdbcType="DECIMAL"/>
<result column="MER_ID" property="merId" jdbcType="VARCHAR"/>
<result column="VERSION" property="version" jdbcType="VARCHAR"/>
<result column="RETURN_CODE" property="returnCode" jdbcType="VARCHAR"/>
......@@ -14,8 +14,8 @@
<result column="CMB_ORDER_ID" property="cmbOrderId" jdbcType="VARCHAR"/>
<result column="RESP_CODE" property="respCode" jdbcType="VARCHAR"/>
<result column="ERR_DESCRIPTION" property="errDescription" jdbcType="VARCHAR"/>
<result column="TXN_AMT" property="txnAmt" jdbcType="NUMBER"/>
<result column="DSC_AMT" property="dscAmt" jdbcType="NUMBER"/>
<result column="TXN_AMT" property="txnAmt" jdbcType="DECIMAL"/>
<result column="DSC_AMT" property="dscAmt" jdbcType="DECIMAL"/>
<result column="CURRENCY_CODE" property="currencyCode" jdbcType="VARCHAR"/>
<result column="PAY_TYPE" property="payType" jdbcType="VARCHAR"/>
<result column="OPEN_ID" property="openId" jdbcType="VARCHAR"/>
......@@ -29,9 +29,9 @@
<result column="ERR_CODE" property="errCode" jdbcType="VARCHAR"/>
<result column="RESP_MSG" property="respMsg" jdbcType="VARCHAR"/>
<result column="CREATION_DATE" property="creationDate" jdbcType="DATE"/>
<result column="CREATED_BY" property="createdBy" jdbcType="NUMBER"/>
<result column="CREATED_BY" property="createdBy" jdbcType="DECIMAL"/>
<result column="LAST_UPDATE_DATE" property="lastUpdateDate" jdbcType="DATE"/>
<result column="LAST_UPDATED_BY" property="lastUpdatedBy" jdbcType="NUMBER"/>
<result column="LAST_UPDATED_BY" property="lastUpdatedBy" jdbcType="DECIMAL"/>
</resultMap>
</mapper>
#招行获取二维码接口
#收款码申请
cmb.qrCodeapplyUrl=https://api.cmburl.cn:8065/polypay/v1.0/mchorders/qrcodeapply
#招行查询订单状态接口
#支付结果查询
cmb.orderQueryUrl=https://api.cmburl.cn:8065/polypay/v1.0/mchorders/orderquery
#招行关闭订单接口
cmb.closeUrl=https://api.cmburl.cn:8065/polypay/v1.0/mchorders/qrcodeapply
#关闭订单
cmb.closeUrl=https://api.cmburl.cn:8065/polypay/v1.0/mchorders/close
#uat环境商户国密私钥
#uat 私钥
cmb.privateKey=D5F2AFA24E6BA9071B54A8C9AD735F9A1DE9C4657FA386C09B592694BC118B38
#uat环境招行国密公钥
#uat 公钥
cmb.publicKey=MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE6Q+fktsnY9OFP+LpSR5Udbxf5zHCFO0PmOKlFNTxDIGl8jsPbbB/9ET23NV+acSz4FEkzD74sW2iiNVHRLiKHg==
cmb.appId=8ab74856-8772-45c9-96db-54cb30ab9f74
......
......@@ -150,12 +150,4 @@ zdw.login.authCode=7b7-f08f197fe2e5
cup.mer.id=000092112092486
cup.upload.file.path=D:\\HCLC_FTP\\CUP_OUT\\
cup.download.file.path=D:\\HCLC_FTP\\CUP_IN\\
cup.init.file.path=F:\\work\\workspace\\IdeaProjects\\hls-support-rlwx\\key\\
cmb.version=0.0.1
cmb.encoding=UTF-8
cmb.signMethod=02
cmb.currencyCode=156
cmb.user.id=N003574551
cmb.mer.id=3089991701201D0
\ No newline at end of file
cup.init.file.path=F:\\work\\workspace\\IdeaProjects\\hls-support-rlwx\\key\\
\ No newline at end of file
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