Ejemplo n.º 1
0
  /*
   * 保存用户基本信息
   */
  public void saveUserInfo(
      String content, IUserService userService, String loginName, String currentUser) {
    // 安全等级
    String secretLevel = "";
    // 身份认证
    String identifyId = "";
    // 身份证有效期限
    String identifyTime = "";
    // 职业
    String major = "";
    // 注册时间:
    String registerDateStr = "";
    // 是否实名认证
    String isRealName = "";
    // 是否会员保障
    String isProtected = "";
    // 手机号
    String phone = "";
    // 是否绑定手机号
    String isPhone = "";
    Date registerDate = null;
    // 姓名
    String name = "";
    // 淘宝账户名
    String taobaoName = "";
    if (content != null && content.trim().length() > 0) {
      Document doc = Jsoup.parse(content);
      Element element = doc.select("ul[class=account-info-det]").get(0);
      Elements lis = element.select("li");
      // 姓名
      name = lis.get(0).select("span").get(1).text();
      RegexPaserUtil rp =
          new RegexPaserUtil(
              "sign_account=", "&", element.html(), RegexPaserUtil.TEXTEGEXANDNRT);
      String s = rp.getText();
      if (s != null) {
        try {
          s = URLDecoder.decode(s, "utf8");
          loginName = s.split("\\^")[1];
          System.out.println(loginName);
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
      }

      // 安全等级
      secretLevel = lis.get(2).select("a").get(0).text();

      // 淘宝账户名
      taobaoName = lis.get(3).select("a").get(0).text();
      if (taobaoName.contains("您还未开通淘宝服务")) {
        taobaoName = "";
      }

      Elements lis2 =
          doc.select("ul[class=account-information fn-clear]")
              .first()
              .select("li")
              .select("div[class=item-name]");
      Elements lis3 =
          doc.select("ul[class=account-information fn-clear]")
              .first()
              .select("li")
              .select("div[class=item-text]");

      for (int i = 0; i < lis2.size(); i++) {
        String question = lis2.get(i).text();
        if (question.contains("身份验证")) {
          identifyId = lis3.get(i).text();
          if (identifyId.contains("通过验证后")) {
            identifyId = "";
          } else {
            identifyId = identifyId.replace("身份证号码", "");
          }
        } else if (question.contains("身份证有效期限")) {
          identifyTime = lis3.get(i).text();
        } else if (question.contains("职业")) {
          major = lis3.get(i).text();
          if (major.contains("未设置 ")) {
            major = "";
          }
        } else if (question.contains("注册时间")) {
          registerDateStr = lis3.get(i).text();
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
          try {
            registerDate = sdf.parse(registerDateStr);
          } catch (ParseException e) {
            // TODO Auto-generated catch block
            logger.info("第434行捕获异常:", e);
            e.printStackTrace();
          }
        }
      }

      Element element1 = doc.select("ul[id=J_used_pro]").get(0);
      Elements lis4 = element1.select("li");
      // 是否实名认证
      isRealName =
          lis4.get(0)
              .select("div[class=account-status-det]")
              .select("p")
              .get(0)
              .select("span")
              .get(0)
              .text();

      // 是否会员保障
      isProtected =
          lis4.get(1)
              .select("div[class=account-status-det]")
              .select("p")
              .get(0)
              .select("span")
              .get(0)
              .text();

      // 是否绑定手机号
      isPhone =
          lis4.get(2)
              .select("div[class=account-status-det]")
              .select("p")
              .get(0)
              .select("span")
              .get(0)
              .text();

      if (isPhone.contains("已绑定")) {
        phone =
            lis4.get(2)
                .select("span[class=mobile-number]")
                .get(0)
                .text()
                .replace("(", "")
                .replace(")", "")
                .trim();
      }
    }
    Date modifyDate = new Date();
    // BaseUser bu = new BaseUser();
    // Map baseMap = new HashMap();
    // baseMap.put("phone", phone);
    // baseMap.put("modifyDate", modifyDate);
    // bu.saveUserInfo(userService, baseMap, currentUser);

    Map<String, String> map = new HashMap<String, String>(2);
    map.put("loginName", loginName);
    map.put("usersource", Constant.ZHIFUBAO);
    List<User> list = userService.getUserByUserNamesource(map);
    if (list != null && list.size() > 0) {
      User user = list.get(0);
      user.setLoginName(loginName);

      user.setPhone(phone);
      user.setRealName(name);
      user.setSecretLevel(secretLevel);
      user.setTaobaoName(taobaoName);
      user.setIdcard(identifyId);
      user.setIdentifyTime(identifyTime);
      user.setMajor(major);
      user.setRegisterDate(registerDate);
      user.setIsRealName(isRealName);
      user.setIsProtected(isProtected);
      user.setIsPhone(isPhone);
      user.setUsersource(Constant.ZHIFUBAO);
      user.setUsersource2(Constant.ZHIFUBAO);
      user.setModifyDate(modifyDate);
      user.setParentId(currentUser);
      userService.update(user);
    } else {
      try {
        User user = new User();
        UUID uuid = UUID.randomUUID();
        user.setId(uuid.toString());
        user.setLoginName(loginName);
        user.setPhone(phone);
        user.setRealName(name);
        user.setSecretLevel(secretLevel);
        user.setTaobaoName(taobaoName);
        user.setIdcard(identifyId);
        user.setIdentifyTime(identifyTime);
        user.setMajor(major);
        user.setRegisterDate(registerDate);
        user.setIsRealName(isRealName);
        user.setIsProtected(isProtected);
        user.setIsPhone(isPhone);
        user.setUsersource(Constant.ZHIFUBAO);
        user.setUsersource2(Constant.ZHIFUBAO);
        user.setParentId(currentUser);
        user.setModifyDate(modifyDate);
        userService.saveUser(user);
      } catch (Exception e) {
        logger.info("第518行捕获异常:", e);
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 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 = "******";
    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 = "******";
    // 检验密码是否符合规范
    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);
      }
    }
  }