Beispiel #1
0
  @Override
  public UserToken login(
      String token,
      String partnerId,
      String serverId,
      long timestamp,
      String sign,
      Map<String, String> params) {
    if (StringUtils.isBlank(token)
        || StringUtils.isBlank(partnerId)
        || StringUtils.isBlank(serverId)
        || timestamp == 0
        || StringUtils.isBlank(sign)) {
      throw new ServiceException(PartnerService.PARAM_ERROR, "参数不正确");
    }

    checkSign(token, partnerId, serverId, timestamp, sign);

    try {
      String[] tokenArr = token.split(":");
      String uid = tokenArr[0];
      String time = tokenArr[1];
      String session = tokenArr[2];
      if (HuCnSdk.instance().verifySession(session, uid, time)) {
        GameServer gameServer = serverListDao.getServerByServerIdAndPartenerId(serverId, partnerId);
        UserToken userToken =
            GameApiSdk.getInstance()
                .loadUserToken(uid, partnerId, serverId, "0", gameServer, params);
        return userToken;
      }

    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw new ServiceException(PartnerService.LOGIN_VALID_FAILD, "登录验证失败");
    }

    throw new ServiceException(PartnerService.LOGIN_VALID_FAILD, "登录验证失败");
  }
Beispiel #2
0
  @Override
  public boolean doPayment(PaymentObj paymentObj) {
    if (paymentObj == null) {
      logger.error("paymentObj为空");
      return false;
    }

    HucnPaymentObj cb = (HucnPaymentObj) paymentObj;

    if (!HuCnSdk.instance().checkPayCallbackSign(cb)) {
      logger.error("签名不正确" + Json.toJson(paymentObj));
      return false;
    }
    logger.info("game id:" + cb.getExtrainfo());
    PaymentOrder order = paymentOrderDao.get(cb.getExtrainfo());

    logger.info("应用订单:" + Json.toJson(order));
    if (order == null) {
      logger.error("订单为空:" + Json.toJson(cb));
      return false;
    }

    if (order.getStatus() == OrderStatus.STATUS_FINISH) {
      logger.error("订单已经完成" + Json.toJson(cb));
      return true;
    }

    BigDecimal finishAmount = new BigDecimal(cb.getAmount());
    if (!cb.getResult().equals("0")) {
      logger.error("充值失败:" + Json.toJson(cb));
      this.paymentOrderDao.updateStatus(
          order.getOrderId(), OrderStatus.STATUS_ERROR, cb.getOrderid(), finishAmount, "");
      return false;
    }
    int gold = (int) (finishAmount.intValue() * 10);
    // 更新订单状态
    if (this.paymentOrderDao.updateStatus(
        order.getOrderId(),
        OrderStatus.STATUS_FINISH,
        cb.getOrderid(),
        finishAmount,
        cb.getExtrainfo())) {
      GameServer gameServer =
          serverListDao.getServerByServerIdAndPartenerId(order.getServerId(), order.getPartnerId());
      // 请求游戏服,发放游戏货币
      if (!GameApiSdk.getInstance()
          .doPayment(
              order.getPartnerId(),
              order.getServerId(),
              order.getPartnerUserId(),
              "",
              order.getOrderId(),
              finishAmount,
              gold,
              "",
              cb.getMsg(),
              gameServer)) {
        // 如果失败,要把订单置为未支付
        this.paymentOrderDao.updateStatus(
            order.getOrderId(),
            OrderStatus.STATUS_NOT_PAY,
            cb.getOrderid(),
            finishAmount,
            cb.getExtrainfo());
        logger.error("发货失败:" + Json.toJson(cb));
        return false;
      } else {
        logger.info("支付成功:" + Json.toJson(cb));
        return true;
      }
    }
    this.paymentOrderDao.updateStatus(
        order.getOrderId(), OrderStatus.STATUS_ERROR, cb.getOrderid(), finishAmount, cb.getMsg());
    logger.error("充值失败:" + Json.toJson(cb));
    return false;
  }