Exemplo n.º 1
0
  // ZLZP
  public static void getImgCheckNum(ValuesObj valuesObj, SimpleDateFormat simpleDateFormat)
      throws ClientProtocolException, IOException {

    ZhaoPinHttpUtil ahaoPinHttpUtil = new ZhaoPinHttpUtil();
    CloseableHttpClient httpClient = ahaoPinHttpUtil.getZhaoPinHttpClient();
    byte[] data = new byte[1024];
    int len = 0;

    HttpGet get =
        new HttpGet(
            "https://passport.zhaopin.com/checkcode/imgrd?r="
                + simpleDateFormat.format(new Date()));
    HttpResponse httpResponse = httpClient.execute(get);
    // String temp_path = FileUtil.getFilePath("config.properties", "temp_path");
    File imgfile = new File("E:/1.jpg");
    OutputStream out = new FileOutputStream(imgfile);
    try {
      //				out = response.getOutputStream();
      if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        InputStream is = httpResponse.getEntity().getContent();
        while ((len = is.read(data)) != -1) {
          out.write(data, 0, len);
        }
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      if (out != null) {
        try {
          out.flush();
        } catch (IOException e) {
          //						 TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
    ImagePreProcess2 imgutile = new ImagePreProcess2();
    try {
      valuesObj.checkcodestr = imgutile.getAllOcr(imgfile);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  // ZLZP
  public static void getZlzpResumeId(ValuesObj valuesObj, SimpleDateFormat simpleDateFormat) {
    LoginResultObj loginResultObj = new LoginResultObj();
    ZhaoPinHttpUtil ahaoPinHttpUtil = new ZhaoPinHttpUtil();
    CloseableHttpClient httpClient = ahaoPinHttpUtil.getZhaoPinHttpClient();
    loginResultObj.setResult(false);
    HttpPost post = null;
    HttpEntity he = null;
    HttpEntity entity = null;
    HttpResponse httpresponse = null;
    List<NameValuePair> loginParames = null;
    String postresult = "";
    try {
      // if ("".equals(valuesObj.loginPointId)) {
      loginParames = new ArrayList<NameValuePair>();
      loginParames.add(new BasicNameValuePair("LoginName", "ep26339738qi"));
      loginParames.add(new BasicNameValuePair("Password", URLEncoder.encode("kuaimaguohe,2015")));
      loginParames.add(new BasicNameValuePair("CheckCode", valuesObj.checkcodestr));
      post = new HttpPost("https://passport.zhaopin.com/org/login");
      post.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
      post.setHeader("Accept-Encoding", "gzip, deflate, plain");
      post.setHeader("Accept-Language", "en-US,en;q=0.5");
      post.setHeader("Cache-Control", "max-age=0");
      post.setHeader("Connection", "keep-alive");
      post.setHeader("Content-Type", "application/x-www-form-urlencoded");

      post.setHeader(
          "User-Agent",
          "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:28.0) Gecko/20100101 Firefox/28.0");
      he = new UrlEncodedFormEntity(loginParames, Consts.UTF_8); // new
      // UrlEncodedFormEntity(loginParames);
      post.setEntity(he);
      httpresponse = httpClient.execute(post);
      entity = httpresponse.getEntity();
      postresult = EntityUtils.toString(entity, "gb2312");
      // System.out.println(postresult);
      int timenum = 0;
      if ("".equals(valuesObj.loginPointId)) {
        while ((postresult.indexOf("%e9%aa%8c%e8%af%81%e7%a0%81%e9%94%99%e8%af%af%ef%bc%81") > 0
                || postresult.indexOf("验证码错误") > 0
                || postresult.indexOf("请输入验证码") > 0)
            && timenum < 20) {
          System.out.println("findind..." + timenum);
          getImgCheckNum(valuesObj, simpleDateFormat);
          System.out.println(valuesObj.checkcodestr);
          loginParames = new ArrayList<NameValuePair>();
          loginParames.add(new BasicNameValuePair("LoginName", "ep26339738qi"));
          loginParames.add(new BasicNameValuePair("Password", "kuaimaguohe,2015"));
          loginParames.add(new BasicNameValuePair("CheckCode", valuesObj.checkcodestr));
          post = new HttpPost("https://passport.zhaopin.com/org/login");
          post.setHeader(
              "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
          post.setHeader("Accept-Encoding", "gzip, deflate, plain");
          post.setHeader("Accept-Language", "en-US,en;q=0.5");
          post.setHeader("Cache-Control", "max-age=0");
          post.setHeader("Connection", "keep-alive");
          post.setHeader("Content-Type", "application/x-www-form-urlencoded");
          post.setHeader(
              "User-Agent",
              "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:28.0) Gecko/20100101 Firefox/28.0");
          he = new UrlEncodedFormEntity(loginParames, Consts.UTF_8); // new
          // UrlEncodedFormEntity(loginParames);
          post.setEntity(he);
          httpresponse = httpClient.execute(post);
          entity = httpresponse.getEntity();
          postresult = EntityUtils.toString(entity, "gb2312");
          // System.out.println(postresult);
          timenum++;
        }
      }
      if (((postresult.indexOf("%e9%aa%8c%e8%af%81%e7%a0%81%e9%94%99%e8%af%af%ef%bc%81") > 0
                  || postresult.indexOf("验证码错误") > 0
                  || postresult.indexOf("请输入验证码") > 0)
              && timenum == 20)
          && "".equals(valuesObj.loginPointId)) {
        loginResultObj.setResult(false);
        loginResultObj.setPostresult("登录失败,请重新登录!");
      } else {
        // 用户名密码错误
        if ((postresult.indexOf("%e9%aa%8c%e8%af%81%e7%a0%81%e9%94%99%e8%af%af%ef%bc%81") > 0
                || postresult.indexOf("用户名或密码错误") > 0)
            && "".equals(valuesObj.loginPointId)) {
          // 用户名密码错误
          loginResultObj.setResult(false);
          loginResultObj.setPostresult("用户名密码错误!");
        } else {
          if ("".equals(valuesObj.loginPointId)) {
            post = new HttpPost("http://rd2.zhaopin.com/s/loginmgr/loginproc_new.asp");

            HttpResponse gethttpresponse1 = httpClient.execute(post);
            HttpEntity getentity1 = gethttpresponse1.getEntity();

            postresult = EntityUtils.toString(getentity1, "gb2312");
            Header[] headers = gethttpresponse1.getHeaders("set-cookie");
            String RDsUserInfo = "";
            for (int i = 0; i < headers.length; i++) {
              String cookie = headers[i].toString();
              if (cookie.indexOf("RDsUserInfo=") > 0) {
                int start = cookie.indexOf("RDsUserInfo=") + 12;
                int end = cookie.indexOf(";", start);
                RDsUserInfo = RDsUserInfo + "RDsUserInfo=" + cookie.substring(start, end);
              }
            }
            post = new HttpPost("http://rd2.zhaopin.com/s/loginmgr/choose.asp");
            RDsUserInfo =
                RDsUserInfo
                    + ";strloginusertype=4;PositionPub_PriorityRule=1;urlfrom2=121123540;adfcid2=topbanner;adfbid2=0;welfaretab=10000";
            post.setHeader("Cookie", RDsUserInfo);
            HttpResponse gethttpresponse = httpClient.execute(post);
            HttpEntity getentity = gethttpresponse.getEntity();
            postresult = EntityUtils.toString(getentity, "gb2312");
            // System.out.println(postresult);
            // 从result中获取跳转URL
            //
            int idstart = postresult.indexOf("id=") + 3;
            int idend = postresult.indexOf("&", idstart);
            valuesObj.loginPointId = postresult.substring(idstart, idend);
            post =
                new HttpPost(
                    "http://rd2.zhaopin.com/s/loginmgr/loginpoint.asp?id="
                        + valuesObj.loginPointId
                        + "&BkUrl=");
            post.setHeader("Cookie", RDsUserInfo);
            HttpResponse gethttpresponse2 = httpClient.execute(post);
            HttpEntity getentity2 = gethttpresponse2.getEntity();
            postresult = EntityUtils.toString(getentity2, "gb2312");
            Header[] headers2 = gethttpresponse2.getHeaders("set-cookie");
            for (int i = 0; i < headers2.length; i++) {
              String cookie = headers2[i].toString();
              if (cookie.indexOf("RDsUserInfo=") > 0) {
                int start = cookie.indexOf("RDsUserInfo=") + 12;
                int end = cookie.indexOf(";", start);
                RDsUserInfo = "RDsUserInfo=" + cookie.substring(start, end);
              }
            }
            RDsUserInfo =
                RDsUserInfo
                    + ";strloginusertype=4;PositionPub_PriorityRule=1;urlfrom2=121123540;adfcid2=topbanner;adfbid2=0;welfaretab=10000";
            valuesObj.rd2cookiestr = RDsUserInfo;
            RDsUserInfo = RDsUserInfo + ";isNewUser=1";
            RDsUserInfo = RDsUserInfo + ";cgmark=2";
            valuesObj.rencaicookiestr = RDsUserInfo;
            valuesObj.rencaicookiestr =
                valuesObj.rencaicookiestr
                    + ";Home_ResultForCustom_searchFrom=custom;Home_ResultForCustom_isOpen=true;Home_ResultForCustom_orderBy=DATE_MODIFIED%2C1;SearchHead_Erd=rd;Home_ResultForCustom_displayMode_JR152722905R90000000000_1=1"
                    + ";pageReferrInSession=http%3A//jobads.zhaopin.com/Position/PositionManage;dywem=95841923.y;"
                    + "__xsptplus30=30.17.1431316853.1431316868.2%234%7C%7C%7C%7C%7C%23%236FxFrrcZFXFF2LRJ4Yr9jydJnSejF3Q9%23;"
                    + "dywez=95841923.1435043849.108.28.dywecsr=rdsearch.zhaopin.com|dyweccn=(referral)|dywecmd=referral|dywectr=undefined|dywecct=/home/resultforcustom;"
                    + "__zpWAM=1434011024152.400411.1434873614.1435043861.8;"
                    + "lastchannelurl=http%3A//rd2.zhaopin.com/portal/myrd/regnew.asp%3Fza%3D2;"
                    + "SearchHistory_StrategyId_1=%2fHome%2fResultForCustom%3fSF_1_1_1%3d%25e9%2594%2580%25e5%2594%25ae%26SF_1_1_27%3d0%26orderBy%3dDATE_MODIFIED%252c1%26exclude%3d1";
            RDsUserInfo = RDsUserInfo + ";fktADClickFlag-success=Y";
            RDsUserInfo =
                RDsUserInfo + ";pageReferrInSession=http%3A//rd2.zhaopin.com/consume/rewardview";
            valuesObj.jobcookiestr = RDsUserInfo;
          }
          post = new HttpPost("http://rd2.zhaopin.com/s/homepage.asp");
          post.setHeader("Cookie", valuesObj.rencaicookiestr);
          HttpResponse gethttpresponse3 = httpClient.execute(post);
          HttpEntity getentity3 = gethttpresponse3.getEntity();
          postresult = EntityUtils.toString(getentity3, "gb2312");

          /*System.out.println("####################################################################################");
          System.out.println(postresult);
          //JM216011950R90250002000
          Pattern pattern=Pattern.compile("^JM[0-9]{9}R[0-9]{11}");
          Matcher matcher=pattern.matcher(postresult.toString());
          while(matcher.find()){
          	System.out.println(matcher.group(1));
          }
          System.out.println("####################################################################################");*/

          if (postresult.indexOf("/s/loginmgr/expire.asp") > 0) {
            valuesObj.loginPointId = "";
            loginResultObj.setResult(false);
          } else {
            // 获取剩余简历数 resumesnum
            int resumesnumstart = postresult.indexOf("<li>剩余下载数:<span class=\"number\"><b>") + 34;
            int resumesnumend = postresult.indexOf("</", resumesnumstart);
            String resumesnum = postresult.substring(resumesnumstart, resumesnumend);
            loginResultObj.setResumesnum(resumesnum);

            // 获取剩余职位数jobsnum

            int jobsnumstart = postresult.indexOf("<li>还可发布职位:<span class=\"number\">") + 32;
            int jobsnumend = postresult.indexOf("</", jobsnumstart);
            String jobsnum = postresult.substring(jobsnumstart, jobsnumend);
            loginResultObj.setJobsnum(jobsnum);
            loginResultObj.setResult(true);
          }
        }
      }
      // }
    } catch (Exception e) {
      if (post != null) {
        post.abort();
      }
      e.printStackTrace();
    } finally {
      if (post != null) {
        post.abort();
      }
    }
  }