Commit 340c1bea authored by 5359's avatar 5359

获取支付二维码接口代码调整

parent 4c63c396
...@@ -40,6 +40,8 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -40,6 +40,8 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
private static final String closeUrl = "https://api.cmburl.cn:8065/polypay/v1.0/mchorders/qrcodeapply"; //UAT private static final String closeUrl = "https://api.cmburl.cn:8065/polypay/v1.0/mchorders/qrcodeapply"; //UAT
private static final String queryUrl = "https://api.cmburl.cn:8065/polypay/v1.0/mchorders/orderquery";
//uat环境商户国密私钥 //uat环境商户国密私钥
public static final String privateKey = "D5F2AFA24E6BA9071B54A8C9AD735F9A1DE9C4657FA386C09B592694BC118B38"; public static final String privateKey = "D5F2AFA24E6BA9071B54A8C9AD735F9A1DE9C4657FA386C09B592694BC118B38";
//uat环境招行国密公钥 //uat环境招行国密公钥
...@@ -50,16 +52,21 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -50,16 +52,21 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
/*接口区分*/ /*接口区分*/
public static final String getQrCode = "GET_QR_CODE"; public static final String getQrCode = "GET_QR_CODE";
public static final String queryQrState = "QUERY_QR_STATE";
/*代扣交易状态*/ /*代扣交易状态*/
public static final String tranSuccess = "SUCCESS";
public static final String transNew = "NEW"; public static final String transNew = "NEW";
public static final String transDeal = "DEAL"; public static final String transDeal = "DEAL";
public static final String transFail = "FAIL"; public static final String transFail = "FAIL";
public static final String transClose = "CLOSED"; public static final String transClose = "CLOSED";
/*交易结果状态*/ /*交易结果状态*/
public static final String cmbSuccess = "SUCCESS"; public static final String orderSuccess = "S";
public static final String cmbFail = "FAIL"; public static final String orderFail = "F";
public static final String orderDelete = "D";
public static final String orderCancel = "C";
public static final String orderPass = "P";
@Value("${cmb.version}") @Value("${cmb.version}")
private String version; private String version;
...@@ -262,12 +269,12 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -262,12 +269,12 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
} }
//验签失败 //验签失败
else if ("4".equalsIgnoreCase(type)) { else if ("4".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, cmbFail); result.put(Constants.RESP_CODE, transFail);
result.put(Constants.RESP_MSG, "验签失败,请检查!"); result.put(Constants.RESP_MSG, "验签失败,请检查!");
} }
//组装请求报文信息失败 //组装请求报文信息失败
else if ("5".equalsIgnoreCase(type)) { else if ("5".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, cmbFail); result.put(Constants.RESP_CODE, transFail);
} }
return result; return result;
} }
...@@ -482,7 +489,6 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -482,7 +489,6 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//返回结果标志 //返回结果标志
String resultType = null; String resultType = null;
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
final String url = "https://api.cmburl.cn:8065/polypay/v1.0/mchorders/orderquery";
//去ld037中查找对应的记录的receiptcfmstatus, //去ld037中查找对应的记录的receiptcfmstatus,
if (Objects.isNull(params.get("recamt_id"))) { if (Objects.isNull(params.get("recamt_id"))) {
...@@ -503,38 +509,37 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -503,38 +509,37 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
HlsEbankCcbTransaction hlsEbankCcbTransaction = hlsEbankCcbTransactionMapper.selectByPrimaryKey(ld037.getTransactionId()); HlsEbankCcbTransaction hlsEbankCcbTransaction = hlsEbankCcbTransactionMapper.selectByPrimaryKey(ld037.getTransactionId());
// HlsEbankCcbTransaction hlsEbankCcbTransaction = createTransaction(ld037) // HlsEbankCcbTransaction hlsEbankCcbTransaction = createTransaction(ld037)
String signResult = getOrderQueryParameter(hlsEbankCcbTransaction); String signResult = getOrderQueryParameter(hlsEbankCcbTransaction);
if (hlsEbankCcbTransaction.getOrderStatus().equals(cmbSuccess)) { // if (hlsEbankCcbTransaction.getOrderStatus().equals(cmbSuccess)) {
result.put(Constants.RESP_CODE, hlsEbankCcbTransaction.getReturnCode()); // result.put(Constants.RESP_CODE, hlsEbankCcbTransaction.getReturnCode());
result.put(Constants.RESP_MSG, hlsEbankCcbTransaction.getReturnMsg()); // result.put(Constants.RESP_MSG, hlsEbankCcbTransaction.getReturnMsg());
// //给到前端订单的状态
// result.put("tradeState", hlsEbankCcbTransaction.getOrderStatus());
// return result;
// }
if (!orderPass.equalsIgnoreCase(hlsEbankCcbTransaction.getOrderStatus())) {
result.put(Constants.RESP_CODE, tranSuccess);
result.put(Constants.RESP_MSG, "订单已完成");
//给到前端订单的状态 //给到前端订单的状态
result.put("tradeState", hlsEbankCcbTransaction.getOrderStatus()); result.put("tradeState", hlsEbankCcbTransaction.getOrderStatus());
return result; return result;
} }
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
Map<String, String> signResultMap = null; Map<String, String> signResultMap = null;
try { try {
signResultMap = mapper.readValue(signResult, Map.class); signResultMap = mapper.readValue(signResult, Map.class);
} catch (IOException e) {
resultType = "5";
e.printStackTrace();
}
long currentTimeMills = System.currentTimeMillis() / 1000;
// 组apiSign加密Map // 组apiSign加密Map
Map<String, String> apiSign = new TreeMap<>(); Map<String, String> apiSign = new TreeMap<>();
apiSign.put("appid", appId); apiSign.put("appid", appId);
apiSign.put("secret", appSecret); apiSign.put("secret", appSecret);
apiSign.put("sign", signResultMap.get("sign")); apiSign.put("sign", signResultMap.get("sign"));
long currentTimeMills = System.currentTimeMillis() / 1000;
apiSign.put("timestamp", "" + currentTimeMills); apiSign.put("timestamp", "" + currentTimeMills);
// MD5加密 // MD5加密
String MD5Content = ""; String MD5Content = "";
try {
MD5Content = SignatureUtil.getSignContent(apiSign); MD5Content = SignatureUtil.getSignContent(apiSign);
} catch (Exception e) {
e.printStackTrace();
}
String apiSignString = MD5Utils.getMD5Content(MD5Content).toLowerCase(); String apiSignString = MD5Utils.getMD5Content(MD5Content).toLowerCase();
// 组request头部Map // 组request头部Map
...@@ -542,57 +547,52 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -542,57 +547,52 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
apiHeader.put("appid", appId); apiHeader.put("appid", appId);
apiHeader.put("timestamp", "" + currentTimeMills); apiHeader.put("timestamp", "" + currentTimeMills);
apiHeader.put("apisign", apiSignString); apiHeader.put("apisign", apiSignString);
//初始化日志
HlsWsRequests hlsWsRequests = logInterfaceRequest(queryQrState, queryUrl, signResult, hlsEbankCcbTransaction.getTransactionId());
logger.info("发送收款码申请请求,请求参数: {}", mapper.writeValueAsString(apiHeader));
//生成HLS_EBANK_CMB_TRANSQRY查询接口交易信息
//发送http请求 //发送http请求
Map<String, String> responseMap = Utils.postForEntity(url, signResult, apiHeader); Map<String, String> responseMap = Utils.postForEntity(queryUrl, signResult, apiHeader);
if (null == responseMap) {
resultType = "3";
logger.info("响应的内容为空");
return result;
}
//处理响应报文 //处理响应报文
Boolean checkResponse = null; Boolean checkResult = checkSign(mapper.writeValueAsString(responseMap));
try {
checkResponse = checkSign(mapper.writeValueAsString(responseMap)); //数据验签
} catch (JsonProcessingException e) { if (!checkResult) {
resultType = "4"; result.put(Constants.RESP_CODE, transFail);
e.printStackTrace(); result.put(Constants.RESP_MSG, "验签失败,请检查!");
return result;
} }
//数据验签成功 if (checkResponse) {
//获取返回码,返回码不为SUCCESS表示报文内的字段不符合规范
//获取返回码、响应码,返回码不为SUCCESS表示报文内的字段不符合规范
String returnCode = responseMap.get("returnCode"); String returnCode = responseMap.get("returnCode");
if ("SUCCESS".equalsIgnoreCase(returnCode)) { if ("SUCCESS".equalsIgnoreCase(returnCode)) {
//响应码 String respCode=responseMap.get("respCode");
String respCode = responseMap.get("returnCode"); if("SUCCESS".equalsIgnoreCase(respCode)){
if ("SUCCESS".equalsIgnoreCase(respCode)) {
//成功拿到订单状态请求的响应 }else{
resultType = "1";
} else {
//请求成功,但是响应结果为失败,传给前端失败原因就行
resultType = "2";
} }
} else { } else {
//返回码都失败
resultType = "3";
}
if (!"1".equalsIgnoreCase(resultType)) {
//更新现金事务表ld037失败处理
updateLd037Fail(ld037, responseMap.get("errCode"));
}
//数据验签失败
else {
//更新现金事务表ld037失败处理
updateLd037Fail(ld037, "SIGN_ERROR");
//直接返回前端验签失败信息,重发或者直接告诉前端发送失败
resultType = "4";
} }
hlsEbankCcbTransaction = setEbankTransactionQR(hlsEbankCcbTransaction, responseMap, resultType); hlsEbankCcbTransaction = setEbankTransactionQR(hlsEbankCcbTransaction, responseMap, resultType);
} catch (IOException e) {
e.printStackTrace();
}
hlsEbankCcbTransactionMapper.updateByPrimaryKeySelective(hlsEbankCcbTransaction); hlsEbankCcbTransactionMapper.updateByPrimaryKeySelective(hlsEbankCcbTransaction);
result = putResult(result, responseMap, resultType);
return result; return result;
} }
/** /**
* 封装请求参数,其中包含商户订单号,作为招行收到请求定位到对应订单的条件 * 封装请求参数,其中包含商户订单号,作为招行收到请求定位到对应订单的条件
* *
...@@ -659,7 +659,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -659,7 +659,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
hlsEbankCcbTransaction.setStatus(transDeal); hlsEbankCcbTransaction.setStatus(transDeal);
hlsEbankCcbTransaction.setOrderStatus("P"); hlsEbankCcbTransaction.setOrderStatus("P");
} else if (response.get("tradeState").equalsIgnoreCase("S")) { } else if (response.get("tradeState").equalsIgnoreCase("S")) {
hlsEbankCcbTransaction.setStatus(cmbSuccess); hlsEbankCcbTransaction.setStatus(tranSuccess);
hlsEbankCcbTransaction.setOrderStatus("S"); hlsEbankCcbTransaction.setOrderStatus("S");
} else if (response.get("tradeState").equalsIgnoreCase("C")) { } else if (response.get("tradeState").equalsIgnoreCase("C")) {
hlsEbankCcbTransaction.setStatus(transClose); hlsEbankCcbTransaction.setStatus(transClose);
...@@ -727,12 +727,12 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -727,12 +727,12 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
} }
//验签失败 //验签失败
else if ("4".equalsIgnoreCase(type)) { else if ("4".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, cmbFail); result.put(Constants.RESP_CODE, transFail);
result.put(Constants.RESP_MSG, "验签失败,请检查!"); result.put(Constants.RESP_MSG, "验签失败,请检查!");
} }
//组装请求报文信息失败 //组装请求报文信息失败
else if ("5".equalsIgnoreCase(type)) { else if ("5".equalsIgnoreCase(type)) {
result.put(Constants.RESP_CODE, cmbFail); result.put(Constants.RESP_CODE, transFail);
} }
return result; return result;
} }
...@@ -780,7 +780,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -780,7 +780,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
/*对请求结果进行保存*/ /*对请求结果进行保存*/
HlsEbankCcbTransaction hlsEbankCcbTransaction = hlsEbankCcbTransactionMapper.selectByPrimaryKey(ld037.getTransactionId()); HlsEbankCcbTransaction hlsEbankCcbTransaction = hlsEbankCcbTransactionMapper.selectByPrimaryKey(ld037.getTransactionId());
hlsEbankCcbTransaction.setStatus(cmbSuccess); hlsEbankCcbTransaction.setStatus(tranSuccess);
hlsEbankCcbTransaction.setOrderStatus("S"); hlsEbankCcbTransaction.setOrderStatus("S");
hlsEbankCcbTransactionMapper.updateByPrimaryKeySelective(hlsEbankCcbTransaction); hlsEbankCcbTransactionMapper.updateByPrimaryKeySelective(hlsEbankCcbTransaction);
......
...@@ -157,3 +157,5 @@ cmb.version=0.0.1 ...@@ -157,3 +157,5 @@ cmb.version=0.0.1
cmb.encoding=UTF-8 cmb.encoding=UTF-8
cmb.signMethod=02 cmb.signMethod=02
cmb.currencyCode=156 cmb.currencyCode=156
cmb.user.id=N003574551
cmb.mer.id=3089991701201D0
\ 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