Exemplo n.º 1
0
  @Override
  public void onGetOrderID(UUser user, UOrder order, ISDKOrderListener callback) {

    if (callback != null) {
      callback.onSuccess(order.getChannel().getPayCallbackUrl());
    }
  }
  @Action("payCallback")
  public void payCallback() {
    try {

      long localOrderID = Long.parseLong(dealseq);

      UOrder order = orderManager.getOrder(localOrderID);

      if (order == null || order.getChannel() == null) {
        Log.d("The order is null or the channel is null.orderID:" + dealseq);
        this.renderState(false, "notifyId 错误");
        return;
      }

      if (order.getState() > PayState.STATE_PAYING) {
        Log.d("The order is already completed.local orderID:%s; orderID:%s", localOrderID, orderid);
        this.renderState(true, "该订单已经被处理,或者CP订单号重复");
        return;
      }

      if (!isValid(order.getChannel())) {
        Log.d("The sign is not valid, sign:%s; orderID:%s", sign, dealseq);
        this.renderState(false, "签名错误");
        return;
      }

      RSAEncrypt encrypt = new RSAEncrypt();
      encrypt.loadPublicKey(order.getChannel().getCpPayKey());
      byte[] dcDataStr = Base64.decode(notify_data);
      byte[] plainData = encrypt.decrypt(encrypt.getPublicKey(), dcDataStr);
      // 获取到加密通告信息
      String notifyDataStr = new String(plainData, "UTF-8");

      Map<String, String> notifyData = HttpUtils.parseUrlParams(notifyDataStr);

      String feeStr = notifyData.containsKey("fee") ? notifyData.get("fee") : null;
      String payresultStr =
          notifyData.containsKey("payresult") ? notifyData.get("payresult") : null;

      int fee = (int) (Float.valueOf(feeStr) * 100);
      int payresult = Integer.valueOf(payresultStr);

      if (order.getMoney() != fee) {

        Log.e(
            "订单金额不一致, local orderID:%s;local money:%s;money:%s",
            localOrderID, fee, order.getMoney());
      }

      if (payresult != 0) {

        Log.e("平台支付失败 local orderID:%s; pay result:%s", localOrderID, payresult);
        this.renderState(false, "联想支付中心返回的结果是支付失败");
        return;
      }

      order.setChannelOrderID(orderid);
      order.setRealMoney(fee);
      order.setSdkOrderTime("");
      order.setCompleteTime(new Date());
      order.setState(PayState.STATE_SUC);
      orderManager.saveOrder(order);
      SendAgent.sendCallbackToServer(this.orderManager, order);
      this.renderState(true, "");

    } catch (Exception e) {
      e.printStackTrace();
      try {
        this.renderState(false, "未知错误");
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
  }
  @Action("payCallback")
  public void payCallback() {
    try {

      LehaihaiPayResult rsp =
          (LehaihaiPayResult) JsonUtils.decodeJson(data, LehaihaiPayResult.class);

      if (rsp == null) {
        Log.e("the data parse failed. data:" + data);
        return;
      }

      long orderID = Long.parseLong(rsp.getExtendsInfo());

      UOrder order = orderManager.getOrder(orderID);

      if (order == null) {
        Log.d("The order is null");
        this.renderState(false);
        return;
      }

      UChannel channel = order.getChannel();
      if (channel == null) {
        Log.d("the channel is null.");
        this.renderState(false);
        return;
      }

      if (order.getState() > PayState.STATE_PAYING) {
        Log.d("The state of the order is complete. The state is " + order.getState());
        this.renderState(true);
        return;
      }

      if (!isSignOK(channel, rsp)) {
        Log.d(
            "The sign verify failed.sign:%s;appKey:%s;orderID:%s",
            rsp.getSign(), channel.getCpPayKey(), rsp.getExtendsInfo());
        this.renderState(false);
        return;
      }

      int moneyInt = (int) (Float.valueOf(rsp.getAmount()) * 100); // 以分为单位

      order.setRealMoney(moneyInt);
      order.setSdkOrderTime(rsp.getTime());
      order.setCompleteTime(new Date());
      order.setChannelOrderID(rsp.getOrderid());
      order.setState(PayState.STATE_SUC);

      orderManager.saveOrder(order);

      SendAgent.sendCallbackToServer(this.orderManager, order);

      renderState(true);

    } catch (Exception e) {
      try {
        renderState(false);
      } catch (IOException e1) {
        e1.printStackTrace();
      }
      e.printStackTrace();
    }
  }
  @Action("payCallback")
  public void payCallback() {
    try {

      WDJPayCallbackContent data =
          (WDJPayCallbackContent) JsonUtils.decodeJson(content, WDJPayCallbackContent.class);

      if (data == null) {
        Log.e("The content parse error...");
        return;
      }

      long localOrderID = Long.parseLong(data.getOut_trade_no());

      UOrder order = orderManager.getOrder(localOrderID);

      if (order == null || order.getChannel() == null) {
        Log.d("The order is null or the channel is null.");
        this.renderState(false, "notifyId 错误");
        return;
      }

      if (order.getState() == PayState.STATE_COMPLETE) {
        Log.d("The state of the order is complete. The state is " + order.getState());
        this.renderState(true, "该订单已经被处理,或者CP订单号重复");
        return;
      }

      int orderMoney = Integer.valueOf(data.getMoney()); // 转换为分

      if (order.getMoney() != orderMoney) {
        Log.e(
            "订单金额不一致! local orderID:"
                + localOrderID
                + "; money returned:"
                + data.getMoney()
                + "; order money:"
                + order.getMoney());
        this.renderState(false, "订单金额不一致");
        return;
      }

      if (isValid(order.getChannel())) {
        order.setChannelOrderID(data.getOrderId());
        order.setState(PayState.STATE_SUC);
        orderManager.saveOrder(order);
        SendAgent.sendCallbackToServer(this.orderManager, order);
        this.renderState(true, "");
      } else {
        order.setChannelOrderID(data.getOrderId());
        order.setState(PayState.STATE_FAILED);
        orderManager.saveOrder(order);
        this.renderState(false, "sign 错误");
      }

    } catch (Exception e) {
      e.printStackTrace();
      try {
        this.renderState(false, "未知错误");
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
  }