Ejemplo n.º 1
0
  private String checkParam(Map<String, String> map) {

    String channelCode = map.get("channelCode");
    String suffix = map.get("suffix");
    String mobile = map.get("mobile");
    String price = map.get("price");
    String amount = map.get("amount");

    // 对后缀名称的校验 ,校验失败则返回xml格式提示
    if (!ApiConstant.SUFFIX_JSON.equals(suffix) && !ApiConstant.SUFFIX_XML.equals(suffix)) {
      BusinessException.raise(ErrorCodeEnum.E_METHOD.getCodeName());
    }

    // 校验手机号
    if (!StringUtils.isBlank(mobile) && !ValidateParams.isPhone(mobile)) {
      BusinessException.raise(ErrorCodeEnum.E_ORDER_PHONE.getCodeName());
    }

    if (!StringUtils.isBlank(amount) && !ValidateParams.isPrice(amount)) {
      BusinessException.raise(ErrorCodeEnum.E_ORDER_AMOUNT.getCodeName());
    }
    if (!StringUtils.isBlank(price) && !ValidateParams.isPrice(price)) {
      BusinessException.raise(ErrorCodeEnum.E_ORDER_AMOUNT.getCodeName());
    }

    // 验证错误会抛出异常
    ApiConstant.checkSystemParam(map);

    return null;
  }
Ejemplo n.º 2
0
  /**
   * 方法用途: <br>
   * 实现步骤: <br>
   *
   * @param ctx
   */
  @RequestMapping(value = "ticket/v2")
  public void ticket(HttpServletRequest request, HttpServletResponse response) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    log.debug("process in ApiServlet.ticket start......");
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter writer = null;
    String returnStr = "";
    String suffix = "";
    String requestPath = request.getRequestURL().toString();
    String ip = ApiConstant.getIpAddr(request);
    log.info("IP:" + ip);
    log.debug("requestPath:" + requestPath);
    Map<String, String> map = getParamterMap(request);
    String channelCode = map.get("channelCode");
    String requestName = map.get("method");
    try {
      writer = response.getWriter();

      String requestCode = requestName.substring(0, requestName.indexOf("."));
      suffix = requestName.substring(requestName.indexOf(".") + 1, requestName.length());

      map.put("suffix", suffix); // 将后缀添加map,方便后续操作	

      // 校验参数 错误会抛出异常
      this.checkParam(map);

      map.put("seckey", "根据不同渠道key不同,TODO");
      // 请求业务码 : 参数、接口名称(如:queryFilms.json)
      returnStr = requestHttpProcess(map, requestName);

    } catch (BusinessException e) {
      returnStr =
          ApiConstant.replaceBack500(
              ErrorCodeEnum.ERROR.getErrorCode() + "", e.getMessage(), suffix);
      log.error("ApiServlet.doPost 操作异常: " + e.getMessage());
    } catch (Exception e) {
      returnStr =
          ApiConstant.replaceBack500(
              ErrorCodeEnum.E_SYSTEM.getErrorCode() + "",
              ErrorCodeEnum.E_SYSTEM.getCodeName(),
              suffix);
      log.error("ApiServlet.doPost 操作异常: ", e);
    }
    log.debug("返回报文:" + returnStr);

    try {
      stopWatch.stop();
      String logKeywords = "[channelCode渠道:" + channelCode + ",method接口:" + requestName + "]";
      loggerUtil.logInfoInterface(
          logKeywords, requestPath, map.toString(), "", stopWatch.getTotalTimeMillis());

    } catch (Exception e) {
      returnStr =
          ApiConstant.replaceBack500(
              ErrorCodeEnum.E_SYSTEM.getErrorCode() + "",
              ErrorCodeEnum.E_SYSTEM.getCodeName(),
              suffix);
      log.error("转换UTF-8异常:", e);
    }
    writer.write(returnStr);
  }