当前位置:编程学习 > XML/UML >>

建设银行支付接口,按日期查询已结算订单xml接口解析(JAVA版)

建行的查询接口不如招行那么全面,建行没有提供按单订单号查询,而且如果你查询的日期没有一笔成功的订单会直接返回一个html告诉你没有信息,并且如果你跨天查询,订单很多很多,他也会返回一个html告诉你订单太多了,无法显示,所以鲁炬这里选择的是,每次只查一天的数据,如果是时间段就用程序分割成一天一天的去查,下面是选择用xml格式查询的解析核心代码。
 
 
 
[java]  
private List<OrderInfo> queryOrderInfoByCcb(String orderDate) {  
  List<OrderInfo> list = new ArrayList<OrderInfo>();  
  String baseUrl = "https://ibsbjstar.ccb.com.cn/app/ccbMain?";  
  String MERCHANTID = this.getBankCono();  
  String BRANCHID = this.getBankBranchid();  
  String POSID = this.getBankPosId();  
  String ORDERDATE = orderDate;  
  String BEGORDERTIME = "00:00:00";  
  String ENDORDERTIME = "23:59:59";  
  String BEGORDERID = this.getBankPwd();  
  String ENDORDERID = "9999999999";  
  String QUPWD = "******";  
  String TXCODE = "410405";  
  String SEL_TYPE = "3";  
  String OPERATOR = "001";  
  String bankURL = "";  
  String result = "";  
  String param = "MERCHANTID=" + MERCHANTID + "&BRANCHID=" + BRANCHID + "&POSID=" + POSID + "&ORDERDATE=" + ORDERDATE  
      + "&BEGORDERTIME=" + BEGORDERTIME + "&ENDORDERTIME=" + ENDORDERTIME + "&BEGORDERID=" + BEGORDERID  
      + "&ENDORDERID=" + ENDORDERID + "&QUPWD=" + QUPWD + "&TXCODE=" + TXCODE + "&SEL_TYPE=" + SEL_TYPE  
      + "&OPERATOR=" + OPERATOR + "&bankURL=" + bankURL + "&result=" + result + "&MAC=";  
  String tmp = "MERCHANTID=" + MERCHANTID + "&BRANCHID=" + BRANCHID + "&POSID=" + POSID + "&ORDERDATE=" + ORDERDATE  
      + "&BEGORDERTIME=" + BEGORDERTIME + "&ENDORDERTIME=" + ENDORDERTIME + "&BEGORDERID=" + BEGORDERID  
      + "&ENDORDERID=" + ENDORDERID + "&QUPWD=&TXCODE=" + TXCODE + "&SEL_TYPE=" + SEL_TYPE + "&OPERATOR=" + OPERATOR;  
  String strMD5 = ByteUtil.byteToChar(MD5Ccb.encode(tmp.getBytes()));  
  String xml = null;  
  try {  
    String url  = baseUrl + param + strMD5;  
    log.debug("发送建行查询http请求:"+url);  
    xml = HttpClientUtil.getHtml(url);  
  } catch(IOException e) {  
    String msg = "建行对账文件获取HTTP访问失败,异常信息:" + e.getMessage();  
    log.error(msg);  
    throw new RuntimeException(msg);  
  }  
  if(xml.contains("您所在查询的IP地址有误")){  
    String msg = "查询日期:"+orderDate+"-建行对账系统提示信息:您所在查询的IP地址被限制访问,请联系建行将服务器地址加入到访问列表中后再进行对账操作。";  
    log.error(msg);  
    throw new RuntimeException(msg);  
  }  
  //根据查询条件未找到记录或记录太多  
  if(xml.contains("根据查询条件未找到记录或记录太多")){  
    String msg = "查询日期:"+orderDate+"-建行对账系统提示信息:根据查询条件未找到记录或记录太多,请修改查询日期。";  
    log.error(msg);  
    return list;  
    //throw new RuntimeException(msg);  
  }  
  xml = xml.trim();  
  log.debug("建行对账文件HTTP获取成功:xml长度:" + xml.length());  
  StringReader stringReader = new StringReader(xml);  
  Document doc = null;  
  try {  
    doc = new SAXReader().read(stringReader);  
  } catch(DocumentException e) {  
    String msg = "建行对账文件XML解析失败,异常信息:" + e.getMessage();  
    log.error(msg);  
    log.error("xml内容:"+xml);  
    throw new RuntimeException(msg);  
  }  
  Element element = doc.getRootElement();  
  List<Element> orders = element.elements();  
  for(Element el : orders) {  
    List<Element> orderContexts = el.elements();  
    double money = 0;//金额  
    String orderNum = null;//订单号  
    String orderStatus = null;//订单状态  
    for(Element orderEl : orderContexts) {  
      //log.debug(orderEl.getName() + " - " + orderEl.getText());  
      if("ORDERID".equals(orderEl.getName())) {  
        orderNum = orderEl.getText();  
      }  
      if("AMOUNT".equals(orderEl.getName())) {  
        money = Double.valueOf(orderEl.getText());  
      }  
      if("STATUS".equals(orderEl.getName()) && "成功".equals(orderEl.getText())) {  
        orderStatus = "0";  
      }  
    }  
    if(money != 0 && !StringUtils.isBlank(orderNum) && !StringUtils.isBlank(orderStatus)) {  
      OrderInfo orderInfo = new OrderInfo();  
      orderInfo.setTradeDate(orderDate);  
      orderInfo.setDealDate(orderDate);  
      orderInfo.setMoney(money);  
      orderInfo.setOrderNum(orderNum);  
      orderInfo.setOrderStatus(orderStatus);  
      list.add(orderInfo);  
    }  www.zzzyk.com
  }  
  log.debug("解析建行对账文件成功:订单明细条数:" + list.size());  
  /*for(OrderInfo orderInfo : list) { 
    log.debug("解析建行对账文件成功:订单明细:" + orderInfo.toString()); 
  }*/  
  log.debug("建行对账文件XML解析完毕!");  
  return list;  
}  
 
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,