记得上下班打卡 | git大法好,push需谨慎

Commit 9276c7f8 authored by anjiabin's avatar anjiabin

修改支付通知逻辑

parent c925b957
......@@ -49,7 +49,7 @@ public abstract class AbstractPayChannelStrategyImpl implements IPayChannelStrat
* @param bankReturnMsg
*/
@Transactional(rollbackFor = Exception.class)
protected void completeSuccessOrder(DragonOrdersDto dragonOrdersDto, String bankTrxNo, LocalDateTime timeEnd, String bankReturnMsg) {
protected boolean completeSuccessOrder(DragonOrdersDto dragonOrdersDto, String bankTrxNo, LocalDateTime timeEnd, String bankReturnMsg) {
log.info("订单支付成功!");
dragonOrdersDto.setPaymentAt(timeEnd);
dragonOrdersDto.setPaymentId(bankTrxNo);// 设置银行流水号
......@@ -59,7 +59,7 @@ public abstract class AbstractPayChannelStrategyImpl implements IPayChannelStrat
//修改订单状态
dragonPayBiz.updateOrderStatus(dragonOrdersDto.getCode(),dragonOrdersDto.getStatus(),bankTrxNo);
//通知商户
dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(dragonOrdersDto));
return dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(dragonOrdersDto));
}
/**
......@@ -67,7 +67,7 @@ public abstract class AbstractPayChannelStrategyImpl implements IPayChannelStrat
* @param dragonOrdersDto
* @param bankReturnMsg
*/
protected void completeFailOrder(DragonOrdersDto dragonOrdersDto, String bankReturnMsg) {
protected boolean completeFailOrder(DragonOrdersDto dragonOrdersDto, String bankReturnMsg) {
log.info("订单支付失败!");
// dragonOrdersDto.setPaymentAt(timeEnd);
// dragonOrdersDto.setPaymentId(bankTrxNo);// 设置银行流水号
......@@ -77,7 +77,7 @@ public abstract class AbstractPayChannelStrategyImpl implements IPayChannelStrat
//修改订单状态
dragonPayBiz.updateOrderStatus(dragonOrdersDto.getCode(),dragonOrdersDto.getStatus(),null);
//通知商户
dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(dragonOrdersDto));
return dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(dragonOrdersDto));
}
}
......@@ -88,7 +88,7 @@ public class PayChannelStrategyAlipayImpl extends AbstractPayChannelStrategyImpl
log.info("接收到{}支付结果{}", payType, notifyMap);
String returnStr = null;
String returnStr = "fail";
String code = notifyMap.get("out_trade_no");
//持久化通知记录
......@@ -112,6 +112,7 @@ public class PayChannelStrategyAlipayImpl extends AbstractPayChannelStrategyImpl
try {
if (AlipaySignature.rsaCheckV1(notifyMap, merchantPubKey, "UTF-8", "RSA2")){
String tradeStatus = notifyMap.get("trade_status");
boolean notifyResult = false;
if (AlipayConstant.AlipayTradeStateEnum.TRADE_SUCCESS.name().equals(tradeStatus)
||AlipayConstant.AlipayTradeStateEnum.TRADE_FINISHED.name().equals(tradeStatus)) {
......@@ -121,18 +122,20 @@ public class PayChannelStrategyAlipayImpl extends AbstractPayChannelStrategyImpl
if (!StringUtil.isEmpty(gmtPaymentStr)) {
timeEnd = DateUtil.Formatter.yyyyMMddHHmmss.parse(gmtPaymentStr);
}
this.completeSuccessOrder(dragonOrdersDto, notifyMap.get("trade_no"), timeEnd, notifyMap.toString());
returnStr = "success";
notifyResult = this.completeSuccessOrder(dragonOrdersDto, notifyMap.get("trade_no"), timeEnd, notifyMap.toString());
} else {
this.completeFailOrder(dragonOrdersDto, notifyMap.toString());
returnStr = "fail";
notifyResult = this.completeFailOrder(dragonOrdersDto, notifyMap.toString());
}
if(notifyResult){
returnStr = "success";
}
} else {// 验证失败
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_ALIPAY_SIGN_ERROR.getCode(),DragonErrorCodeEnum.TRADE_ALIPAY_SIGN_ERROR.getMessage());
log.error("alipay notify fail code:{} msg:{} ",DragonErrorCodeEnum.TRADE_ALIPAY_SIGN_ERROR.getCode(),DragonErrorCodeEnum.TRADE_ALIPAY_SIGN_ERROR.getMessage());
return returnStr;
}
} catch (AlipayApiException e) {
log.error("验签失败:" , e);
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_ALIPAY_SIGN_ERROR.getCode(),DragonErrorCodeEnum.TRADE_ALIPAY_SIGN_ERROR.getMessage());
log.error("alipay notify fail 验签失败:e:{}" , e);
log.error("alipay notify fail 验签失败:code:{} msg:{}" ,DragonErrorCodeEnum.TRADE_ALIPAY_SIGN_ERROR.getCode(),DragonErrorCodeEnum.TRADE_ALIPAY_SIGN_ERROR.getMessage());
}
log.info("返回支付通道{}信息{}", payType, returnStr);
......
......@@ -91,6 +91,7 @@ public class PayChannelStrategyWepayImpl extends AbstractPayChannelStrategyImpl
}
String sign = notifyMap.remove("sign");
boolean notifyResult = false;
if (PayWepayUtils.getInstance().notifySign(notifyMap, sign)) {// 根据配置信息验证签名
if (WepayConstant.WeixinTradeStateEnum.SUCCESS.getCode().equals(notifyMap.get("result_code"))) {// 业务结果
// 成功
......@@ -99,13 +100,15 @@ public class PayChannelStrategyWepayImpl extends AbstractPayChannelStrategyImpl
if (!StringUtil.isEmpty(timeEndStr)) {
timeEnd = DateUtil.Formatter.yyyyMMddHHmmssTrim.parse(timeEndStr);
}
this.completeSuccessOrder(dragonOrdersDto, notifyMap.get("transaction_id"), timeEnd, notifyMap.toString());
returnStr = "<xml>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <return_msg><![CDATA[OK]]></return_msg>\n" + "</xml>";
notifyResult = this.completeSuccessOrder(dragonOrdersDto, notifyMap.get("transaction_id"), timeEnd, notifyMap.toString());
} else {
this.completeFailOrder(dragonOrdersDto, notifyMap.toString());
notifyResult = this.completeFailOrder(dragonOrdersDto, notifyMap.toString());
}
if(notifyResult){
returnStr = "<xml>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <return_msg><![CDATA[OK]]></return_msg>\n" + "</xml>";
}
} else {
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_WEPAY_SIGN_ERROR.getCode(),DragonErrorCodeEnum.TRADE_WEPAY_SIGN_ERROR.getMessage());
log.error("wepay notify fail code:{} msg:{} ",DragonErrorCodeEnum.TRADE_WEPAY_SIGN_ERROR.getCode(),DragonErrorCodeEnum.TRADE_WEPAY_SIGN_ERROR.getMessage());
}
} catch (Exception e) {
e.printStackTrace();
......
......@@ -85,7 +85,6 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_ERROR_NOT_EXISTS.getCode(),DragonErrorCodeEnum.TRADE_ERROR_NOT_EXISTS.getMessage());
}
//通知商户
dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(ordersDto));
return false;
return dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(ordersDto));
}
}
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