Exemplo n.º 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);

    logger.info("Vivo token:" + token);
    try {
      String uid = VivoSdk.instance().getUid(token);
      if (uid != null) {
        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, "登录验证失败");
  }
Exemplo n.º 2
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, "登录验证失败");
  }
Exemplo n.º 3
0
  @Override
  public boolean doPayment(PaymentObj paymentObj) {
    if (paymentObj == null) {
      logger.error("paymentObj为空");
      return false;
    }

    VivoPaymentObj cb = (VivoPaymentObj) paymentObj;
    if (!VivoSdk.instance().checkPayCallbackSign(cb)) {
      logger.error("签名不正确" + Json.toJson(paymentObj));
      return true;
    }

    logger.info("game id:" + cb.getStoreOrder());
    PaymentOrder order = paymentOrderDao.get(cb.getStoreOrder());

    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.getOrderAmount());
    if (!cb.getRespCode().equals("0000")) {
      logger.error("充值失败:" + Json.toJson(cb));
      this.paymentOrderDao.updateStatus(
          order.getOrderId(), OrderStatus.STATUS_ERROR, cb.getVivoOrder(), finishAmount, "");
      return true;
    }

    int gold = (int) (order.getAmount().doubleValue() * 10);
    // 更新订单状态
    if (this.paymentOrderDao.updateStatus(
        order.getOrderId(), OrderStatus.STATUS_FINISH, cb.getVivoOrder(), finishAmount, "")) {
      GameServer gameServer =
          serverListDao.getServerByServerIdAndPartenerId(order.getServerId(), order.getPartnerId());
      // 请求游戏服,发放游戏货币
      if (!GameApiSdk.getInstance()
          .doPayment(
              order.getPartnerId(),
              order.getServerId(),
              order.getPartnerUserId(),
              "",
              order.getOrderId(),
              finishAmount,
              gold,
              "",
              "",
              gameServer)) {
        // 如果失败,要把订单置为未支付
        this.paymentOrderDao.updateStatus(
            order.getOrderId(), OrderStatus.STATUS_NOT_PAY, cb.getVivoOrder(), finishAmount, "");
        logger.error("发货失败:" + Json.toJson(cb));
        return false;
      } else {
        logger.info("支付成功:" + Json.toJson(cb));
        return true;
      }
    }
    this.paymentOrderDao.updateStatus(
        order.getOrderId(), OrderStatus.STATUS_ERROR, cb.getVivoOrder(), finishAmount, "");
    logger.error("充值失败:" + Json.toJson(cb));
    return false;
  }
Exemplo n.º 4
0
  @Override
  public boolean doPayment(PaymentObj paymentObj) {
    if (paymentObj == null) {
      logger.error("paymentObj为空");
      return false;
    }
    HongKongPaymentObj cb = (HongKongPaymentObj) paymentObj;
    JSONObject jsonObject = HongKongSdk.instance().checkPayCallbackSign(cb);
    if (jsonObject == null) {
      logger.error("签名不正确" + Json.toJson(paymentObj));
      return false;
    }
    logger.info("game id:" + jsonObject.getString("developerPayload"));
    String orderId = null;
    try {
      PrivateKey privateKey = RSAHelper.getPrivateKey(HongKongSdk.instance().getPrivateKey());
      // 加解密类
      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.DECRYPT_MODE, privateKey);
      byte[] deBytes = cipher.doFinal(Base64.decode(jsonObject.getString("developerPayload")));
      orderId = new String(deBytes);
      logger.info("game decode id:" + orderId);
    } catch (Exception e) {
      logger.error("decode error!", e);
    }
    PaymentOrder order = paymentOrderDao.get(orderId);

    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 = order.getAmount();
    if (!"0".equals(jsonObject.getString("purchaseState"))) {
      logger.error("充值失败:" + Json.toJson(cb));
      this.paymentOrderDao.updateStatus(
          order.getOrderId(), OrderStatus.STATUS_ERROR, order.getOrderId(), finishAmount, "");
      return false;
    }

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