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); } } }
/* * 下载验证码 */ public String downloadFile( HttpClient httpclient, String url, String dataPath, String picName, String hostUrl, String refererUrl) throws Exception { String authcodePath = InfoUtil.getInstance().getInfo("road", "authcodePath"); String path1 = authcodePath + "/" + dataPath; File file2 = new File(path1); if (!file2.exists() && !file2.isDirectory()) { file2.mkdir(); } String destfilename = path1 + "/" + picName; HttpGet httpget = new HttpGet(url); httpget.setHeader("Accept", "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5"); httpget.setHeader("Accept-Encoding", "gzip, deflate"); httpget.setHeader("Accept-Language", "zh-CN"); if (hostUrl != null && hostUrl.length() > 0) { httpget.setHeader("Host", hostUrl); } if (refererUrl != null && refererUrl.length() > 0) { httpget.setHeader("Referer", refererUrl); } httpget.setHeader( "User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/7.0)"); File file = new File(destfilename); if (file.exists()) { file.delete(); } HttpResponse response = httpclient.execute(httpget); if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { // 请求成功 // 取得请求内容 HttpEntity entity = response.getEntity(); // 显示内容 if (entity != null) { // 这里可以得到文件的类型 如image/jpg /zip /tiff 等等 // 但是发现并不是十分有效,有时明明后缀是.rar但是取到的是null,这点特别说明 System.out.println(entity.getContentType()); // 可以判断是否是文件数据流 System.out.println(entity.isStreaming()); // 设置本地保存的文件 FileOutputStream output = new FileOutputStream(destfilename); // 得到网络资源并写入文件 InputStream input = entity.getContent(); byte b[] = new byte[1024]; int j = 0; while ((j = input.read(b)) != -1) { output.write(b, 0, j); } output.flush(); output.close(); } if (entity != null) { entity.consumeContent(); } } PicUpload fupload = new PicUpload(); fupload.upload(file.getAbsolutePath()); return picName; }
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 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); } } } } }