コード例 #1
0
  private boolean isSignOK(UChannel channel, LehaihaiPayResult rsp) {
    StringBuilder sb = new StringBuilder();
    sb.append("amount=")
        .append(rsp.getAmount())
        .append("gameid=")
        .append(rsp.getGameid())
        .append("orderid=")
        .append(rsp.getOrderid())
        .append("serverid=")
        .append(rsp.getServerid())
        .append("time=")
        .append(rsp.getTime())
        .append("uid=")
        .append(rsp.getUid())
        .append(channel.getCpAppSecret());

    Log.d("sign txt:" + sb.toString());

    String md5 = EncryptUtils.md5(sb.toString()).toLowerCase();

    Log.d("md5:" + md5);

    return md5.equals(rsp.getSign());
  }
コード例 #2
0
  @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();
    }
  }