예제 #1
0
  private Response send(Request req) {

    String reqXml = JaxbUtil.toXml(req, ENCODING, Request.class);
    // 签名
    String signData = reqXml.replace("<SIGNED_MSG></SIGNED_MSG>", "");
    String signMsg = sign(signData);
    reqXml =
        reqXml.replace("<SIGNED_MSG></SIGNED_MSG>", "<SIGNED_MSG>" + signMsg + "</SIGNED_MSG>");

    log.info("请求报文:" + reqXml);
    String responseXml = HttpClientUtils.post(requestUrl, reqXml, ENCODING);
    log.info("响应报文:" + responseXml);

    Response response = JaxbUtil.toBean(responseXml, Response.class);

    // 验签
    String verifyData =
        responseXml.substring(0, responseXml.indexOf("<SIGNED_MSG>"))
            + responseXml.substring(responseXml.indexOf("</SIGNED_MSG>") + 13);
    if (!verify(verifyData, response.getINFO().getSIGNED_MSG())) {
      log.error("银联-验签响应报文失败!");
      throw new SysException("银联-验签响应报文失败!");
    }
    return response;
  }
예제 #2
0
  /**
   * 下载对账文件
   *
   * @param date 日期
   * @param type 收付类型:S-代收;F代付
   */
  public void downSettleFile(String date, String type) {

    String reqtime = DateUtil.format(new Date(), DateUtil.FULL_PATTERN_1);
    String reqUrl =
        downUrl
            + "?SETT_DATE="
            + date
            + "&SETT_NO=01&SF_TYPE="
            + type
            + "&USER_NAME="
            + username
            + "&MERCHANT_ID="
            + merchantId
            + "&REQ_TIME="
            + reqtime
            + "&SIGNED_MSG=";

    String signData = date + "|01|" + username + "|" + merchantId + "|" + reqtime;
    String signMsg = sign(signData);
    reqUrl += signMsg;

    log.info("下载请求报文:" + reqUrl);
    String filename = null;
    if ("S".equals(type)) {
      filename = date + "01_ds.txt";
    } else if ("F".equals(type)) {
      filename = date + "01_df.txt";
    }
    String filepath = settleFileDir + "/" + date + "/" + filename;
    HttpClientUtils.down(reqUrl, filepath);
  }