public String weChatNotify(String request) {
    try {
      Map<String, String> reqParams = WeChatUtils.decodeXML(request);

      if (reqParams == null) {
        return WeChatUtils.buildNotifyFailXML();
      }
      if (!Constants.WECHAT_CODE_RET_SUCCESS.equals(reqParams.get("return_code"))) {
        return WeChatUtils.buildNotifyFailXML();
      }
      if (!Constants.WECHAT_CODE_RET_SUCCESS.equals(reqParams.get("result_code"))) {
        return WeChatUtils.buildNotifyFailXML();
      }

      // 回调通知信息入库
      insertPayNotify(reqParams);

      // 订单信息更新
      PayOrder payOrderUpdate = updatePayOrderByPayChannel(reqParams, Constants.PAY_CHANNEL_WECHAT);

      // 通知O2O
      String outNotifyUrl = payOrderUpdate.getOutNotifyUrl();
      int payId = payOrderUpdate.getPayId();
      String outOrderId = payOrderUpdate.getOutOrderId();
      String retCode = payOrderUpdate.getPayStatus();
      String retMsg = payOrderUpdate.getPayChnDesc();
      String merPriv = payOrderUpdate.getMerPriv();

      notifyService.notifyO2O(outNotifyUrl, payId, outOrderId, retCode, retMsg, merPriv);

      return WeChatUtils.buildNotifySUCCESSXML();
    } catch (Exception e) {
      return WeChatUtils.buildNotifyFailXML();
    }
  }
  public AlipayNotifyResp alipayNotify(AlipayNotifyReq alipayNotifyReq) {
    if ("WAIT_BUYER_PAY".equals(alipayNotifyReq.getNotifyParams().get("trade_status"))) {
      // 支付宝通知状态是"WAIT_BUYER_PAY"时候, 则不入库、不通知o2o
      return new AlipayNotifyResp(true);
    }

    /* 数据入库 */
    PayOrder order = operaDBbyNotify(alipayNotifyReq.getNotifyParams());
    if (order == null) {
      return new AlipayNotifyResp(false);
    }

    // 通知O2O
    String outNotifyUrl = order.getOutNotifyUrl();
    int payId = order.getPayId();
    String outOrderId = order.getOutOrderId();
    String retCode = order.getPayStatus();
    String retMsg = order.getPayChnDesc();
    String merPriv = order.getMerPriv();

    notifyService.notifyO2O(outNotifyUrl, payId, outOrderId, retCode, retMsg, merPriv);

    return new AlipayNotifyResp(true);
  }
  public String umpNotify(HttpServletRequest request, NotifyReq reqParam) {
    try {
      // 记录回调日志
      PayNotify payNotify = new PayNotify();
      payNotify.setNotifyText(reqParam.toString());
      if (!daoService.insertPayNotify(payNotify)) {
        LOGGER.error("insertPayNotify fail: notifyText=" + reqParam.toString());
      }

      // 验证签名
      if (!UmpUtils.validateNotifySign(request, reqParam)) {
        return UmpUtils.buildNotifyResponse(
            reqParam, Constants.UMP_CODE_VERIFY_SIGN_FAIL, Constants.UMP_MSG_VERIFY_SIGN_FAIL);
      }

      // 查询该订单号是否存在
      String outOrderId = reqParam.getOrderId();
      String outSysId = Constants.OUT_SYS_ID_UMP;

      PayOrder payOrder = daoService.queryPayOrderByOutOrderIdAndOutSysId(outOrderId, outSysId);
      if (payOrder == null) {
        return UmpUtils.buildNotifyResponse(
            reqParam,
            Constants.UMP_CODE_QUERY_BY_OUT_ORDER_ID_NOT_EXIT,
            Constants.UMP_MSG_QUERY_BY_OUT_ORDER_ID_NOT_EXIT);
      }

      // 用户首次支付, 则记录用户协议编号
      if (reqParam.getUsrPayAgreementId() != null) {
        String userId = payOrder.getMerUserId();
        PayAgreement userPayAgreement = daoService.queryPayAgreementByUserId(userId);
        // 未签订协议,则插入协议表
        if (userPayAgreement == null) {
          // 插入失败,则记录日志信息
          if (!daoService.insertPayAgreement(userId, reqParam)) {
            LOGGER.error("notify insert pay_agreement fail");
          }
        }
      }

      // 更新交易状态
      String tradeStatus = reqParam.getTradeState();
      String tradeCode = CommonUtils.getTransCodeByTradeStatus(tradeStatus);
      PayOrder payOrderUpdate = UmpUtils.buildNotifyUpdatePayOrder(tradeCode, tradeStatus);

      if (!daoService.updatePayOrderByOutOrderIdAndOutSysId(payOrderUpdate, outOrderId, outSysId)) {
        return UmpUtils.buildNotifyResponse(
            reqParam, Constants.UMP_CODE_UPDATE_ORDER_FAIL, Constants.UMP_MSG_UPDATE_ORDER_FAIL);
      }

      // 通知O2O
      String retCode = payOrderUpdate.getPayStatus();
      String retMsg = payOrderUpdate.getPayChnDesc();
      String outNotifyUrl = payOrder.getOutNotifyUrl();
      int payId = payOrder.getPayId();
      String merPriv = payOrder.getMerPriv();

      notifyService.notifyO2O(outNotifyUrl, payId, outOrderId, retCode, retMsg, merPriv);

      // 构建返回信息
      return UmpUtils.buildNotifyResponse(
          reqParam,
          Constants.UMP_RETURN_CODE_CLIENT_SUCCESS,
          Constants.UMP_RETURN_MSG_CLIENT_SUCCESS);
    } catch (Exception e) {
      LOGGER.error("umpNotify error: reqParam=" + reqParam, e);
      return UmpUtils.buildNotifyResponse(
          reqParam, Constants.UMP_RETURN_CODE_CLIENT_FAIL, Constants.UMP_RETURN_MSG_CLIENT_FAIL);
    }
  }
Ejemplo n.º 4
0
 private void notifyOtherNodes(String dataId, String group) {
   notifyService.notifyConfigInfoChange(dataId, group);
 }