예제 #1
0
  public void startToCustomer() {
    String payReisKey = TConfigLoader.getProperty("ali.refund.redistopic", "alirefundtopic");
    String msg = redisDao.blpop(payReisKey);
    log.info("start alirefund redis cusomer .......");
    while (true) {
      try {
        log.info("receive redis msg refund : " + msg);
        List<TradeRefund> refundList = msgHandle(msg);
        for (TradeRefund tradeRefund : refundList) {
          notifyRefundService.refundSuccess(tradeRefund, tradeRefund.getRefundMoney());
        }
      } catch (Exception e) {
        log.error("", e);
        redisDao.rpush(payReisKey + "error", msg);
      }

      msg = redisDao.blpop(payReisKey);
    }
  }
예제 #2
0
  private List<TradeRefund> msgHandle(String msg) {
    AliRefundNotifyParam refundNotifyParam = JSON.parseObject(msg, AliRefundNotifyParam.class);
    String batchNo = refundNotifyParam.getBatch_no();
    String redetail = refundNotifyParam.getResult_details();
    int succesNum = Integer.parseInt(refundNotifyParam.getSuccess_num());

    String[] reundStrs = redetail.split(";");
    List<TradeRefund> refundList = new ArrayList<TradeRefund>();
    for (String refundStr : reundStrs) {
      String[] refundInfos = refundStr.split("\\^");
      if (refundInfos.length == 3) {
        String tradeNo = refundInfos[0];
        double refundMoney = Double.parseDouble(refundInfos[1]);
        String refundResult = refundInfos[2];

        TradePayment tradePayment = paymentService.queryByTradeNo(tradeNo);
        TradeRefund tradeRefund =
            notifyRefundService.queryRefundByBathNOOrderNo(
                tradePayment.getPayNo(), tradePayment.getOrderNo());
        if ("SUCCESS".equalsIgnoreCase(refundResult)) {
          if (!tradeRefund.getRefundMoney().equals(refundMoney)) {
            tradeRefund.setRefundError("退款通知 金额 [" + refundMoney + "] 和 退款金额不等 ");
          }
          RefundStatus refundStatus = RefundStatus.getType(tradeRefund.getRefundStatus());
          if (refundStatus.equals(RefundStatus.UNKNOWN)) {
            tradeRefund.setRefundStatus(RefundStatus.SUCCESS.value);
          } else {
            log.warn(tradeRefund.getRefundNo() + " 退款状态可能异常" + refundStatus + " ");
            tradeRefund.setRefundStatus(RefundStatus.SUCCESS.value);
          }
          tradeRefund.setRefundResponse(msg);
          refundList.add(tradeRefund);
        } else {
          log.info(tradePayment.getOrderNo() + "支付宝 退款 失败 " + msg);
        }
      } else {
        log.error("支付宝 退款 格式错误 " + msg);
      }
    }

    return refundList;
  }