private void saveSmsLog(
      SimpleObject context,
      final int page,
      final int t,
      final Date d,
      final String dstr,
      final int isHistory) {
    String text = ContextUtil.getContent(context);
    Document doc = ContextUtil.getDocumentOfContent(context);
    System.out.println(doc.toString());
    if (text.indexOf("没有查找到相关数据") >= 0) {
      return;
    }
    String tableSort = InfoUtil.getInstance().getInfo("dx/sh", "tableSort");
    String tbody = InfoUtil.getInstance().getInfo("dx/sh", "tbody");
    String tr = InfoUtil.getInstance().getInfo("dx/sh", "tr");
    String td = InfoUtil.getInstance().getInfo("dx/sh", "td");
    Elements elements = doc.select(tableSort);
    if (elements != null && elements.size() > 0) {
      Elements elements2 = elements.first().select(tbody).first().select(tr);
      for (int j = 0; j < elements2.size(); j++) {
        try {
          Elements tds = elements2.get(j).select(td);
          if (tds.size() == 5) {
            String RecevierPhone = tds.get(2).text().trim(); // 对方号码
            String SentTime = tds.get(1).text().trim(); // 发送时间
            String BusinessType = tds.get(3).text().trim(); // 费用类型
            String AllPay = tds.get(4).text().trim(); // 费用

            Date sentTime = null;
            try {
              sentTime = DateUtils.StringToDate(SentTime, "yyyy-MM-dd HH:mm:ss");
            } catch (Exception e) {
              e.printStackTrace();
            }
            TelcomMessage obj = new TelcomMessage();
            obj.setPhone(phoneNo);
            UUID uuid = UUID.randomUUID();
            obj.setId(uuid.toString());
            obj.setBusinessType(BusinessType); // 业务类型:点对点
            obj.setRecevierPhone(RecevierPhone); // 对方号码
            obj.setSentTime(sentTime); // 发送时间
            obj.setCreateTs(new Date());
            obj.setAllPay(Double.parseDouble(AllPay)); // 总费用
            messageList.add(obj);
          }

        } catch (Exception e) {
          logger.error("saveSmsLog", e);
        }
      }
      if (text.contains("下一页")) {
        requestSmsLogService(page + 1, 1, d, dstr, isHistory);
      }
    }
  }
Example #2
0
  public static void main(String[] args) {
    DefaultHttpClient httpclient = CUtil.init();
    HBYidong hbYidong = new HBYidong();

    String text = hbYidong.getText(httpclient, firstUrl);
    text = hbYidong.getText(httpclient, indexUrl);
    String authUrls = authUrl + System.currentTimeMillis();
    String currentUser = "eewerew";
    try {
      String authImg = hbYidong.getAuthcode(httpclient, currentUser);
      System.out.println(authImg);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //		Scanner in2 = new Scanner(System.in);
    //		System.out.print("密码为:");
    //		String password = in2.nextLine();

    Scanner in = new Scanner(System.in);
    System.out.print("验证码为:");
    String authcode = in.nextLine();
    String phone = "13971146032";
    String password = "418840";
    // 检验密码是否符合规范
    Map map1 = hbYidong.checkPassword(password);
    Boolean flag1 = Boolean.valueOf(map1.get("flag").toString());
    if (flag1) {
      // 第一次登陆
      Map map = new HashMap();
      map.put("accountType", "0");
      map.put("username", phone);
      map.put("passwordType", "1");
      map.put("password", password);
      map.put("smsRandomCode", "");
      map.put("validateCode", authcode);
      map.put("action", "/SSO/loginbox"); //
      map.put("style", "mymobile");
      map.put("service", "my");
      map.put("continue", "");
      map.put("submitMode", "login");
      map.put("guestIP", "219.143.103.242");
      text = hbYidong.login(httpclient, loginUrl, map);
      System.out.println(text);

      //
      if (text != null && text.contains("SAMLart")) { // 验证第一步登陆成功
        // 跳转
        Document doc = Jsoup.parse(text);
        // RelayState=&SAMLart=a6d8028d8d0a4bc2a37f8998fbc3c441&PasswordType=1&errorMsg=
        String actionUrl = doc.select("form[id=sso]").attr("action");
        String elayState = doc.select("input[name=elayState]").attr("value");
        String SAMLart = doc.select("input[name=SAMLart]").attr("value");
        String PasswordType = doc.select("input[name=PasswordType]").attr("value");
        String errorMsg = doc.select("input[name=errorMsg]").attr("value");
        Map map2 = new HashMap();
        map2.put("elayState", elayState);
        map2.put("SAMLart", SAMLart);
        map2.put("PasswordType", PasswordType);
        map2.put("errorMsg", errorMsg);
        text = hbYidong.login(httpclient, actionUrl, map2);
        System.out.println(text);

        Map mapnull = new HashMap();
        text = hbYidong.postText(httpclient, login2, mapnull);
        text = hbYidong.getText(httpclient, payUrl1);

        // 解析用户基本信息
        text = hbYidong.getText(httpclient, userinfoUrl);
        System.out.println(text);
        Document userdoc = Jsoup.parse(text);
        Elements elements =
            userdoc.select("div[class=acc_chax]").first().select("table").first().select("tr");
        for (int i = 0; i < elements.size(); i++) {
          Element element = elements.get(i);
          Elements elements2 = element.select("th");
          for (int j = 0; j < elements2.size(); j++) {
            Element element2 = elements2.get(j);
            String value = element.select("td").get(j).text();
            String key = element2.text();
            if (key.contains("客户姓名")) {
              System.out.println("客户姓名:" + value);
            } else if (key.contains("用户性别")) {
              System.out.println("用户性别:" + value);
            } else if (key.contains("证件号码")) {
              System.out.println("证件号码:" + value);
            } else if (key.contains("入网时间")) {
              System.out.println("入网时间:" + value);
            }
          }
        }

        // 开始解析当月账单:加上当前总共6个月
        //
        //	http://www.hb.10086.cn/service/fee/queryNewInvoice!commitServiceNew.action?postion=outer
        //				当月qryMonthType=current&theMonth=201407&menuid=myBill&groupId=tabs3
        //				qryMonthType=history&theMonth=201402&menuid=myBill&groupId=tabs3
        //				qryMonthType=history&theMonth=201406&menuid=myBill&groupId=tabs3
        List<String> months = DateUtils.getMonths(6, "yyyyMM");
        for (int i = 0; i < months.size(); i++) {
          Map cmap = new LinkedHashMap();
          String theMonth = months.get(i);
          String qryMonthType = "history";
          String menuid = "myBill";
          String groupId = "tabs3";
          if (DateUtils.isEqual(theMonth)) { // 判断是否是当前月
            qryMonthType = "current";
          }
          cmap.put("qryMonthType", qryMonthType);
          cmap.put("theMonth", theMonth);
          cmap.put("menuid", menuid);
          cmap.put("groupId", groupId);

          text = hbYidong.postText(httpclient, payUrl, cmap);
          System.out.println(text);
          Document paydoc = Jsoup.parse(text);

          Elements payelements = paydoc.select("div[class=fyxx]").first().select("tr");
          for (int j = 0; j < payelements.size(); j++) {
            Element payelement = payelements.get(j);
            Elements payDetails = payelement.select("td");
            System.out.println(j + "--" + payDetails.get(0).text() + "---" + payDetails.get(2));
          }
        }

        // 第三步:发送动态验证码

      } else { // 登陆出错
        // 打印出错信息
        RegexPaserUtil rp =
            new RegexPaserUtil("errorMsg=\"", "\"", text, RegexPaserUtil.TEXTEGEXANDNRT);
        String errorMeg = rp.getText();
        System.out.println(errorMeg);
      }
    }
  }
  private void saveOnlineFlow(
      SimpleObject context,
      final int page,
      final int t,
      final Date d,
      final String dstr,
      final int isHistory,
      final String date) {
    String text = ContextUtil.getContent(context);
    Document doc = ContextUtil.getDocumentOfContent(context);
    System.out.println(doc.toString());
    DianXinFlow dxFlow = new DianXinFlow();
    UUID uuid = UUID.randomUUID();
    dxFlow.setId(uuid.toString());
    dxFlow.setPhone(phoneNo);

    Date queryMonth = DateUtils.StringToDate(date, "yyyy/MM");
    // 查询日期
    dxFlow.setQueryMonth(queryMonth);
    String cycle = "";
    if (isHistory == 0) {
      cycle = date + "/01-" + DateUtils.formatDate(new Date(), "yyyy/MM/dd");
    } else {
      cycle = date + "/01-" + DateUtils.lastDayOfMonth(date, "yyyy/MM", "yyyy/MM/dd");
    }
    dxFlow.setDependCycle(cycle);
    if (text.indexOf("没有查找到相关数据") >= 0) {
      if (page == 1) {
        dxFlow.setAllFlow(new BigDecimal(0));
        dxFlow.setAllTime(new BigDecimal(0));
        dxFlow.setAllPay(new BigDecimal(0.00));
        flowList.add(dxFlow);
      }
    } else {
      if (page == 1) {
        Elements tables = doc.select("table");
        if (isHistory == 0) {
          Element tr1 = tables.get(1).select("tr").get(1);
          String allpay = tr1.select("td").get(3).text().replaceAll("元", "").trim();
          if (allpay.equals("")) {
            allpay = "0";
          }
          String allTime = tr1.select("td").get(5).text().trim();
          String allFlow = tr1.select("td").get(7).text().trim();

          dxFlow.setAllFlow(new BigDecimal(allpay));
          dxFlow.setAllTime(new BigDecimal(StringUtil.flowTimeFormat(allTime)));
          dxFlow.setAllPay(new BigDecimal(StringUtil.flowFormat(allFlow)));
          flowList.add(dxFlow);
        } else {
          Element tr1 = tables.get(2).select("tr").get(1);
          String allpay = tr1.select("td").get(3).text().replaceAll("元", "").trim();
          if (allpay.equals("")) {
            allpay = "0";
          }
          String allTime = tr1.select("td").get(5).text().trim();
          String allFlow = tr1.select("td").get(7).text().trim();

          dxFlow.setAllFlow(new BigDecimal(allpay));
          dxFlow.setAllTime(new BigDecimal(StringUtil.flowTimeFormat(allTime)));
          dxFlow.setAllPay(new BigDecimal(StringUtil.flowFormat(allFlow)));
          flowList.add(dxFlow);
        }
      }
      String tableSort = InfoUtil.getInstance().getInfo("dx/sh", "tableSort");
      String tbody = InfoUtil.getInstance().getInfo("dx/sh", "tbody");
      String tr = InfoUtil.getInstance().getInfo("dx/sh", "tr");
      String td = InfoUtil.getInstance().getInfo("dx/sh", "td");
      Elements elements = doc.select(tableSort);
      if (elements != null && elements.size() > 0) {
        Elements elements2 = elements.first().select(tbody).first().select(tr);
        for (int j = 0; j < elements2.size(); j++) {
          try {
            Elements tds = elements2.get(j).select(td);
            if (tds.size() == 9 && isHistory == 1) {
              String beginTime = tds.get(3).text().trim(); // 开始时间
              String fee = tds.get(8).text().trim().replaceAll("元", ""); // 费用(元)
              // String RecevierPhone = tds.get(2).text().trim();// 对方号码
              String netType = tds.get(1).text().trim(); // 通讯类型
              // String time_flow = tds.get(4).text().trim();// 时长/流量(分钟/KB)
              int tradeTime =
                  TimeUtil.timetoint_HH_mm_ss(
                      tds.get(5)
                          .text()
                          .trim()
                          .replaceAll("小时", ":")
                          .replaceAll("分", ":")
                          .replaceAll("秒", "")); // 上网时长
              String flow = tds.get(6).text().trim().replaceAll("KB", ""); // 总流量
              String business = tds.get(7).text().trim(); // 漫游类型
              Date beginTimeDate = null;
              BigDecimal feeDecimal = new BigDecimal(0);
              BigDecimal flows = new BigDecimal(0);
              try {
                beginTimeDate = DateUtils.StringToDate(beginTime, "yyyy-MM-dd HH:mm:ss");
                feeDecimal = new BigDecimal(fee);
                flows = new BigDecimal(flow);
              } catch (Exception e) {
                e.printStackTrace();
              }
              DianXinFlowDetail obj = new DianXinFlowDetail();
              obj.setPhone(phoneNo);
              obj.setBeginTime(beginTimeDate);
              obj.setFee(feeDecimal);
              obj.setNetType(netType);
              obj.setTradeTime(tradeTime);
              obj.setFlow(flows);
              obj.setBusiness(business);
              flowDetailList.add(obj);
            } else if (tds.size() == 8 && isHistory == 0) {
              String beginTime = tds.get(1).text().trim(); // 开始时间
              String fee = tds.get(2).text().trim().replaceAll("元", ""); // 费用(元)
              // String RecevierPhone = tds.get(2).text().trim();// 对方号码
              String netType = tds.get(3).text().trim(); // 通讯类型
              // String time_flow = tds.get(4).text().trim();// 时长/流量(分钟/KB)
              int tradeTime =
                  TimeUtil.timetoint_HH_mm_ss(
                      tds.get(5)
                          .text()
                          .trim()
                          .replaceAll("小时", ":")
                          .replaceAll("分", ":")
                          .replaceAll("秒", "")); // 上网时长
              int flow = Integer.parseInt(tds.get(6).text().trim().replaceAll("KB", "")); // 总流量
              String business = tds.get(7).text().trim(); // 漫游类型
              Date beginTimeDate = null;
              BigDecimal feeDecimal = new BigDecimal(0);
              try {
                beginTimeDate = DateUtils.StringToDate(beginTime, "yyyy-MM-dd HH:mm:ss");
                feeDecimal = new BigDecimal(fee);
              } catch (Exception e) {
                e.printStackTrace();
              }
              DianXinFlowDetail obj = new DianXinFlowDetail();
              obj.setPhone(phoneNo);
              obj.setBeginTime(beginTimeDate);
              obj.setFee(feeDecimal);
              obj.setNetType(netType);
              obj.setTradeTime(tradeTime);
              obj.setFlow(new BigDecimal(flow));
              obj.setBusiness(business);
              flowDetailList.add(obj);
            }

          } catch (Exception e) {
            logger.error("saveSmsLog", e);
          }
        }
        if (text.contains("下一页")) {
          if (text.contains("下一页")) {
            if (isHistory == 1) requestOnlineFlowService(page + 1, 2, d, dstr, isHistory, date);
            else requestThisMonthService(page + 1, t, "", "", isHistory);
          }
        }
      }
    }
  }
  private void saveCallLog(
      SimpleObject context,
      final int page,
      final int t,
      final Date d,
      final String dstr,
      final int isHistory) {
    String text = ContextUtil.getContent(context);
    Document doc = ContextUtil.getDocumentOfContent(context);
    System.out.println(doc.toString());
    if (text.indexOf("没有查找到相关数据") >= 0) {
      return;
    }
    String tableSort = InfoUtil.getInstance().getInfo("dx/sh", "tableSort");
    String tbody = InfoUtil.getInstance().getInfo("dx/sh", "tbody");
    String tr = InfoUtil.getInstance().getInfo("dx/sh", "tr");
    String td = InfoUtil.getInstance().getInfo("dx/sh", "td");
    Elements elements = doc.select(tableSort);
    if (elements != null && elements.size() > 0) {
      Elements elements2 = elements.first().select(tbody).first().select(tr);
      for (int j = 0; j < elements2.size(); j++) {
        try {
          Elements elements3 = elements2.get(j).select(td);

          String tradeType = elements3.get(1).text(); // 通话类型
          String date = elements3.get(2).text();
          Date cTime = DateUtils.StringToDate(date, "yyyy-MM-dd HH:mm:ss"); // 通话开始时间
          String tradeTime = elements3.get(3).text(); // 通信时长
          String callWay = elements3.get(4).text(); // 呼叫类型
          String recevierPhone = elements3.get(5).text(); // 对方号码
          String tradeAddr = elements3.get(6).text(); // 通信地点
          BigDecimal basePay = new BigDecimal(elements3.get(7).text()); // 基本费用
          BigDecimal longPay = new BigDecimal(elements3.get(8).text()); // 长途费用
          BigDecimal infoPay = new BigDecimal(elements3.get(9).text()); // 信息费用
          BigDecimal otherPay = new BigDecimal(elements3.get(10).text()); // 其他费用
          BigDecimal allPay = new BigDecimal(elements3.get(11).text()); // 总费用

          int tradeTimeInt = new TimeUtil().timetoint(tradeTime);
          DianXinDetail dxDetail = new DianXinDetail();
          UUID uuid = UUID.randomUUID();
          dxDetail.setId(uuid.toString());
          dxDetail.setcTime(cTime);
          dxDetail.setTradeTime(tradeTimeInt);
          dxDetail.setTradeAddr(tradeAddr);
          dxDetail.setTradeType(tradeType);
          dxDetail.setCallWay(callWay);
          dxDetail.setRecevierPhone(recevierPhone);
          dxDetail.setBasePay(basePay);
          dxDetail.setLongPay(longPay);
          dxDetail.setInfoPay(infoPay);
          dxDetail.setOtherPay(otherPay);
          dxDetail.setAllPay(allPay);
          dxDetail.setPhone(phoneNo);
          detailList.add(dxDetail);
        } catch (Exception e) {
          logger.error("saveCallLog", e);
        }
      }
      /*
       * if(!content.contains("下一页")){ break; }
       */
      if (text.contains("下一页")) {
        if (isHistory == 1) requestCallLogService(page + 1, 1, d, dstr, isHistory);
        else requestThisMonthService(page + 1, t, "", "", isHistory);
      }
    }
  }
  private void requestService() {
    Date d = new Date();
    for (int i = 0; i < 7; i++) {
      final Date cd = DateUtils.add(d, Calendar.MONTH, -1 * i);
      String dstr = DateUtils.formatDate(cd, "yyyy/MM");
      // 当前月查询
      try {
        if (i == 0) {
          requestThisMonthService(
              1,
              0,
              DateUtils.formatDate(DateUtils.add(d, Calendar.MONTH, 0), "yyyy/MM") + "/01",
              DateUtils.formatDate(DateUtils.add(d, Calendar.MONTH, 0), "yyyy/MM/dd"),
              0); // t==0表示语音,1表示短信,2表示流量
          requestThisMonthService(
              1,
              1,
              DateUtils.formatDate(DateUtils.add(d, Calendar.MONTH, 0), "yyyy/MM") + "/01",
              DateUtils.formatDate(DateUtils.add(d, Calendar.MONTH, 0), "yyyy/MM/dd"),
              0); // t==0表示语音,1表示短信,2表示流量
          requestThisMonthService(
              1,
              2,
              DateUtils.formatDate(DateUtils.add(d, Calendar.MONTH, 0), "yyyy/MM") + "/01",
              DateUtils.formatDate(DateUtils.add(d, Calendar.MONTH, 0), "yyyy/MM/dd"),
              0); // t==0表示语音,1表示短信,2表示流量
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    // 历史查询
    for (int i = 0; i < 6; i++) {
      final Date cd = DateUtils.add(d, Calendar.MONTH, -1 * i);
      String dstr = DateUtils.formatDate(cd, "yyyy/MM");

      final Date cd1 = DateUtils.add(d, Calendar.MONTH, (-1 * i) - 1);
      String date = DateUtils.formatDate(cd1, "yyyy/MM");

      requestOnlineFlowService(1, 1, cd, dstr, 1, date);
      requestCallLogService(1, 1, cd, dstr, 1);
      requestSmsLogService(1, 1, cd, dstr, 1);
    }

    parseBalanceInfo();
    // 查不出来账单
    // requestMonthBillService();
  }