Ejemplo n.º 1
0
  public static List<QueryPVisitor> confirmTicket(List<Long> ticketList)
      throws DataException, IOException, DocumentException {
    String msgIdValue = System.currentTimeMillis() + "";
    String reqIdValue = "802";
    StringBuffer sb = new StringBuffer();
    for (Long id : ticketList) {
      sb.append(id + ",");
    }
    sb.delete(sb.length() - 1, sb.length());
    Map<String, String> ParamMap = new LinkedHashMap<String, String>();
    ParamMap.put("ReqId", reqIdValue);
    ParamMap.put("MsgId", msgIdValue);
    ParamMap.put("ReqParam", sb.toString());
    ParamMap.put("ReqKey", MD5.md5(reqIdValue + msgIdValue + sb.toString() + key).toLowerCase());

    String returnString = HttpclientUtil.Utf8HttpClientUtils(reUrl, ParamMap);
    Document doc = DocumentHelper.parseText(returnString);
    Element root = doc.getRootElement();
    Element ticket;
    QueryPVisitor queryPVisitor;
    List<QueryPVisitor> returnTicketList = Lists.newArrayList();
    for (Iterator i = root.elementIterator("Ticket"); i.hasNext(); ) {
      ticket = (Element) i.next();
      queryPVisitor = new QueryPVisitor();
      ticket.accept(queryPVisitor);
      returnTicketList.add(queryPVisitor);
    }
    if (returnTicketList.isEmpty()) {
      Document document = DocumentHelper.parseText(returnString);
      queryPVisitor = new QueryPVisitor();
      document.accept(queryPVisitor);
      returnTicketList.add(queryPVisitor);
    }
    return returnTicketList;
  }
Ejemplo n.º 2
0
  public List<CpResultVisitor> sendTicket(List<Ticket> ticketList)
      throws DataException, IOException, DocumentException {

    Document document = DocumentHelper.createDocument();
    /** 建立XML文档的根 */
    Element rootElement = document.addElement("ReqParam");
    rootElement.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    rootElement.addAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
    for (Ticket ticket : ticketList) {
      Map<String, String> paramMap = buildPeqParamValue(ticket);
      Element ticketElement = rootElement.addElement("Ticket");
      for (String key : paramMap.keySet()) {
        String value = paramMap.get(key);
        Element element = ticketElement.addElement(key);
        element.setText(value);
      }
    }
    String peqParamValue = "<?xml version=\"1.0\"?>" + rootElement.asXML();
    String msgIdValue = System.currentTimeMillis() + "";
    String reqIdValue = "801";

    Map<String, String> ParamMap = new LinkedHashMap<String, String>();
    ParamMap.put("ReqId", reqIdValue);
    ParamMap.put("MsgId", msgIdValue);
    ParamMap.put("ReqParam", peqParamValue);
    ParamMap.put(
        "ReqKey",
        SecurityUtil.md5((reqIdValue + msgIdValue + peqParamValue + key).getBytes("UTF-8"))
            .toLowerCase());

    // ParamMap.put("ReqKey",
    // SecurityUtil.md5(reqIdValue+msgIdValue+peqParamValue+key).toLowerCase());

    // String url = getReUrl(reqIdValue,msgIdValue,peqParamValue);

    String returnString = HttpclientUtil.Utf8HttpClientUtils(reUrl, ParamMap);
    Document doc = DocumentHelper.parseText(returnString);
    Element root = doc.getRootElement();
    List<CpResultVisitor> returnList = Lists.newArrayList();
    for (Iterator i = root.elementIterator("Ticket"); i.hasNext(); ) {
      String ResultId = null;
      String OrderId = null;
      try {
        Element element = (Element) i.next();
        ResultId = element.selectSingleNode("ResultId").getText();
        OrderId = element.selectSingleNode("OrderId").getText();
        CpResultVisitor cpResultVisitor = new CpResultVisitor();
        /// 是否成功
        if (StringUtils.isNotBlank(ResultId)) {
          if (String.valueOf("0").equals(ResultId.trim())
              || String.valueOf("2").equals(ResultId.trim())) {
            /// 0成功2重复
            cpResultVisitor.setIsSuccess(Boolean.TRUE);
          }
          cpResultVisitor.setResult(ResultId);
        }
        if (StringUtils.isNotBlank(OrderId)) {
          cpResultVisitor.setOrderId(OrderId);
        }
        returnList.add(cpResultVisitor);
      } catch (Exception e) {
        logger.error("发送彩票出现错误[ResultId]" + ResultId + "[OrderId]" + OrderId + e.getMessage());
        continue;
      }
    }
    return returnList;
  }