protected void ssoLogin1(SimpleObject context) {
   Request req1 = ContextUtil.getRequest(context);
   Integer scode = (Integer) req1.getExtra(Request.STATUS_CODE);
   if (HttpUtil.isMovedStatusCode(scode)) {
     HttpResponse resp = ContextUtil.getResponse(context);
     Header h1 = resp.getFirstHeader("Location");
     String nexturl = h1.getValue();
     if (nexturl == null) {
       logger.error("Error : No Redirect URL");
     } else {
       Request req = new Request(nexturl);
       req.setCharset(UAM_CHAR_SET);
       req.addObjservers(
           new AbstractProcessorObserver(util, WaringConstaint.ZGDX_7) {
             @Override
             public void afterRequest(SimpleObject context) {
               ssoLogin1(context);
             }
           });
       spider.addRequest(req);
     }
   } else {
     endSSOLogin(context);
   }
 }
 protected void parseLoginPage(SimpleObject context, final String prefix, final String phone) {
   Request req1 = ContextUtil.getRequest(context);
   Integer scode = (Integer) req1.getExtra(Request.STATUS_CODE);
   // DebugUtil.printCookieData(ContextUtil.getCookieStore(context), null);
   if (HttpUtil.isMovedStatusCode(scode)) {
     HttpResponse resp = ContextUtil.getResponse(context);
     Header h1 = resp.getFirstHeader("Location");
     String nexturl = h1.getValue();
     if (nexturl == null) {
       logger.error("Error : No Redirect URL");
     } else {
       nexturl = fixedFullUrl(nexturl);
       Request req = new Request(nexturl.replaceAll(" ", "%20"));
       req.setCharset(UAM_CHAR_SET);
       req.putHeader("Referer", "http://www.189.cn/dqmh/login/loginJT.jsp");
       req.addObjservers(
           new AbstractProcessorObserver(util, WaringConstaint.ZGDX_2) {
             @Override
             public void afterRequest(SimpleObject context) {
               parseLoginPage(context, prefix, phone);
             }
           });
       spider.addRequest(req);
     }
   } else {
     if (prefix != null) {
       // com.lkb.debug.DebugUtil.printCookieData(ContextUtil.getCookieStore(context), null);
       saveVerifyImage(context, prefix, phone);
     } else {
       parseLoginStep2(context);
     }
   }
 }
예제 #3
0
  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);
      }
    }
  }
  protected void parseLoginStep2(SimpleObject context) {
    String text = ContextUtil.getContent(context);
    if (text == null) {
      return;
    }
    String phone1 = phoneNo;
    String password1 = password;

    String n = StringUtil.subStr("strEnc(username,", ");", text).trim();
    if (!StringUtils.isBlank(n)) {
      String[] stra = n.trim().replaceAll("\'", "").split(",");
      // pwd, digit, f, s
      phone1 = executeJsFunc("des/tel_com_des.js", "strEnc", phoneNo, stra[0], stra[1], stra[2]);
      password1 =
          executeJsFunc("des/tel_com_des.js", "strEnc", password, stra[0], stra[1], stra[2]);
    }
    Document doc = ContextUtil.getDocumentOfContent(context);

    Elements form = doc.select("form#c2000004");

    Request req = new Request(fixedFullUrl(form.attr("action")));
    req.setMethod("POST");
    req.initNameValuePairs(12);

    req.addNameValuePairs("lt", form.select("input[name=lt]").attr("value"));
    req.addNameValuePairs("_eventId", "submit");
    req.addNameValuePairs("forbidpass", "null");

    req.addNameValuePairs("areaname", areaName);
    req.addNameValuePairs("password", password1);
    req.addNameValuePairs("authtype", "c2000004");

    req.addNameValuePairs("customFileld01", customField1);

    req.addNameValuePairs("customFileld02", customField2);
    req.addNameValuePairs("forbidaccounts", "null");
    req.addNameValuePairs("open_no", "c2000004");
    req.addNameValuePairs("username", phone1);
    req.addNameValuePairs("randomId", authCode == null ? "" : authCode);
    req.setCharset(UAM_CHAR_SET);
    req.addObjservers(
        new AbstractProcessorObserver(util, WaringConstaint.ZGDX_3) {
          @Override
          public void afterRequest(SimpleObject context) {
            parseLoginStep3(context);
          }
        });
    spider.addRequest(req);
  }
  private void parseLoginStep4(SimpleObject context) {
    Document doc = ContextUtil.getDocumentOfContent(context);
    Elements e1 = doc.select("form#c2000004");
    if (e1.size() > 0) {
      data.put("errMsg", e1.select("td#status2").text());
      setStatus(STAT_STOPPED_FAIL);
      notifyStatus();
      return;
    }
    e1 = doc.select("form#login_form");
    if (e1.size() > 0) {
      data.put("errMsg", "登录失败,请重试!");
      setStatus(STAT_STOPPED_FAIL);
      notifyStatus();
      return;
    }
    String text = ContextUtil.getContent(context);

    String url =
        StringUtil.subStr(
            "<script type='text/javascript'>location.replace('", "');</script>", text);
    if (StringUtils.isBlank(url.trim())) {

      if ("IBM HTTP Server".equalsIgnoreCase(doc.select("title").text())) {
        setStatus(STAT_LOGIN_SUC);
        // notifyStatus();
        ssoLogin(context);
      } else {
        data.put("fail", true);
        setStatus(STAT_STOPPED_FAIL);
        notifyStatus();
        logger.error("Login Fail.....");
      }

      return;
    }
    getUrl(
        url,
        null,
        new Object[] {UAM_CHAR_SET},
        new AbstractProcessorObserver(util, WaringConstaint.ZGDX_5) {
          @Override
          public void afterRequest(SimpleObject context) {
            setStatus(STAT_LOGIN_SUC);
            ssoLogin(context);
          }
        });
  }
 private void ssoLogin2(SimpleObject context) {
   Request req1 = ContextUtil.getRequest(context);
   Integer scode = (Integer) req1.getExtra(Request.STATUS_CODE);
   if (HttpUtil.isMovedStatusCode(scode)) {
     HttpResponse resp = ContextUtil.getResponse(context);
     Header h1 = resp.getFirstHeader("Location");
     String nexturl = h1.getValue();
     if (nexturl == null) {
       logger.error("Error : No Redirect URL");
     } else {
       ssoLogin2(context);
     }
   } else {
     completeLogin(context);
   }
 }
 private void endSSOLogin(SimpleObject context) {
   String text = ContextUtil.getContent(context);
   String url = null;
   if (text != null) {
     Document doc = ContextUtil.getDocumentOfContent(context);
     Elements es = doc.select("script");
     for (int i = 0; i < es.size(); i++) {
       String html = es.get(i).html();
       if (html.indexOf("location.replace") >= 0) {
         url = StringUtil.subStr("location.replace(", ");", html);
         url = url.substring(1, url.length() - 1);
         break;
       }
     }
     /*text = text.replaceAll("<script type='text/javascript'>", "<script>").replaceAll("<script type='javascript'>", "<script>");
     url = StringUtil.subStr("<script>location.replace('", "');</script>", text);*/
   }
   if (!StringUtils.isBlank(url)) {
     getUrl(
         url,
         null,
         new AbstractProcessorObserver(util, WaringConstaint.ZGDX_8) {
           /*@Override
           public void preparedData(SimpleObject context) {
           	super.preparedData(context);
           	if (ContextUtil.getError(context) != null) {
           		completeLogin(context);
           	}
           }*/
           public void afterRequest(SimpleObject context) {
             ssoLogin1(context);
           }
         });
   } else {
     // notifyStatus();
     completeLogin(context);
   }
 }
예제 #8
0
 protected void onCompleteLogin(SimpleObject context) {
   // <script
   // language="javascript">top.location="/service/uiss_mobileLogin.do?method=login
   // logger.info(ContextUtil.getContent(context));
   // com.lkb.debug.DebugUtil.printCookieData(ContextUtil.getCookieStore(context),
   // "sh.189.cn");
   String text = ContextUtil.getContent(context);
   if (text != null && text.indexOf("service/uiss_mobileLogin.do?method=login") >= 0) {
     setStatus(STAT_LOGIN_SUC);
     getUrl("http://sh.189.cn/service/uiss_mobileLogin.do?method=login", null, null);
   } else {
     setStatus(STAT_STOPPED_FAIL);
     data.put("errMsg", "登录失败, 请重试!");
   }
 }
예제 #9
0
  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);
      }
    }
  }
예제 #10
0
  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);
          }
        }
      }
    }
  }