Package com.belerweb.social.exception

Examples of com.belerweb.social.exception.SocialException


    try {
      HttpResponse response = http.execute(request);
      StatusLine statusLine = response.getStatusLine();
      if (statusLine == null || statusLine.getStatusCode() != HttpStatus.SC_OK
          || response.getEntity() == null) {
        throw new SocialException(String.valueOf(statusLine));
      }
      String result = IOUtils.toString(response.getEntity().getContent(), "GB18030");
      request.releaseConnection();
      List<Group> groups = null;
      Document doc = Jsoup.parse(result);
      Elements scripts = doc.select("script");
      for (Element el : scripts) {
        for (DataNode node : el.dataNodes()) {
          String script = node.getWholeData().trim();
          if (script.startsWith("var goListData")) {
            ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
            List<User> users = new ArrayList<User>();
            Bindings bindings = engine.createBindings();
            bindings.put("users", users);
            script =
                script
                    + "(function(){for(var i in goListData.oList){var o=goListData.oList[i];var u=new com.belerweb.social.qq.mail.bean.User();u.setId(o.sId);u.setType(o.sItemType);u.setLevel(o.sLevel);u.setName(o.oName.length?o.oName[0].sVal:'');u.setFamilyName((o.oFamilyName&&o.oFamilyName.length)?o.oFamilyName[0].sVal:'');u.setGivenName((o.oGivenName&&o.oGivenName.length)?o.oGivenName[0].sVal:'');u.setCustom((o.oCustom&&o.oCustom.length)?o.oCustom[0].sVal:'');u.setNickName((o.oQQNickName&&o.oQQNickName.length)?o.oQQNickName[0].sVal:'');u.setRelate((o.oRelate&&o.oRelate.length)?o.oRelate[0].sVal:'');u.setUrl((o.oUrl&&o.oUrl.length)?o.oUrl[0].sVal:'');u.setDate((o.oDate&&o.oDate.length)?o.oDate[0].sVal:'');u.setBirthday((o.oBirthday&&o.oBirthday.length)?o.oBirthday[0].sVal:'');u.setIm((o.oIM&&o.oIM.length)?o.oIM[0].sVal:'');u.setNote((o.oNote&&o.oNote.length)?o.oNote[0].sVal:'');var es=new java.util.ArrayList();for(var j in o.oEmail){var obj=o.oEmail[j];var e=new com.belerweb.social.qq.mail.bean.Email();e.setEmail(obj.sVal);e.setLabel(obj.sLabel?obj.sLabel:'');e.setType(obj.sType?obj.sType:'');es.add(e)}u.setEmails(es);var ts=new java.util.ArrayList();for(var j in o.oTel){var obj=o.oTel[j];var t=new com.belerweb.social.qq.mail.bean.Tel();t.setNum(obj.sVal);t.setLabel(obj.sLabel?obj.sLabel:'');t.setType(obj.sType?obj.sType:'');ts.add(t)}u.setTels(ts);if(o.oOrg&&o.oOrg.length){var org=new com.belerweb.social.qq.mail.bean.Org();org.setOrg1(o.oOrg[0].sOrg1);org.setOrg2(o.oOrg[0].sOrg2);org.setTitle(o.oOrg[0].sTitle);u.setOrg(org)}if(o.oAdr&&o.oAdr.length){var adr=new com.belerweb.social.qq.mail.bean.Address();adr.setLabel(o.oAdr[0].sLabel);adr.setType(o.oAdr[0].sType);adr.setCountry(o.oAdr[0].sCountry);adr.setProvince(o.oAdr[0].sProvince);adr.setCity(o.oAdr[0].sCity);adr.setStreet(o.oAdr[0].sStreet);adr.setPostcode(o.oAdr[0].sPostcode);u.setAddress(adr)}users.add(u)}})();";
            if (group.getId() == null) {
              groups = new ArrayList<Group>();
              bindings.put("groups", groups);
              script =
                  script
                      + "(function(){for(var k in goGroupData){for(var i in goGroupData[k].oList){var obj=goGroupData[k].oList[i];var g=new com.belerweb.social.qq.mail.bean.Group();g.setId(obj.sId);g.setType(obj.sSubType);g.setName(obj.sName);groups.add(g);}}})();";
            }
            engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
            engine.eval(script);
            group.setUsers(users);
          }
        }
      }
      return groups;
    } catch (ClientProtocolException e) {
      throw new SocialException(e);
    } catch (IOException e) {
      throw new SocialException(e);
    } catch (ScriptException e) {
      throw new SocialException(e);
    }
  }
View Full Code Here


      request.addHeader(new BasicHeader("Accept-Language", "zh-cn,zh"));
      HttpResponse response = http.execute(request);
      StatusLine statusLine = response.getStatusLine();
      if (statusLine == null || statusLine.getStatusCode() != HttpStatus.SC_OK
          || response.getEntity() == null) {
        throw new SocialException(String.valueOf(statusLine));
      }
      String result = IOUtils.toString(response.getEntity().getContent());
      request.releaseConnection();
      String[] str = result.substring(7, result.length() - 1).split(",");
      if (!"0".equals(str[0].trim().substring(1, str[0].length() - 1))) {
        throw new SocialException(str[4]);
      }

      request = new HttpGet(str[2].trim().substring(1, str[2].length() - 1));
      response = http.execute(request);
      statusLine = response.getStatusLine();
      if (statusLine == null || statusLine.getStatusCode() != HttpStatus.SC_OK
          || response.getEntity() == null) {
        throw new SocialException(String.valueOf(statusLine));
      }
      result = IOUtils.toString(response.getEntity().getContent(), "GB18030");
      request.releaseConnection();
      Matcher matcher = PATTERN.matcher(result);
      if (matcher.find()) {
        this.sid = matcher.group(1);
      } else {
        if (!result.contains("看不清")) {
          Document doc = Jsoup.parse(result);
          Elements scripts = doc.select("script");
          boolean status = false;
          for (Element el : scripts) {
            for (DataNode node : el.dataNodes()) {
              String script = node.getWholeData().trim();
              if (script.startsWith("var urlHead")) {
                ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
                script = script.replace("window.location.replace(targetUrl);", "");
                try {
                  engine.eval(script);
                  String url = engine.get("targetUrl").toString();
                  request = new HttpGet(url);
                  response = http.execute(request);
                  result = IOUtils.toString(response.getEntity().getContent(), "GB18030");
                  status = true;
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            }
          }
          if (!status) {
            // throw new SocialException("没有获取到sid");
          }
        }
        vc = yundama.decode(getValidationCode2(), YundamaType.ALPHABETIC4).getResult();
        params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("btlogin", "登录"));
        params.add(new BasicNameValuePair("delegate_url", ""));
        params.add(new BasicNameValuePair("sid", ""));
        params.add(new BasicNameValuePair("uin", email.substring(0, email.indexOf("@"))));
        params.add(new BasicNameValuePair("verifycode", vc));
        params.add(new BasicNameValuePair("vt", "passport"));
        HttpPost post = new HttpPost("https://mail.qq.com/cgi-bin/login?sid=");
        post.setConfig(RequestConfig.custom().setRedirectsEnabled(false)
            .setRelativeRedirectsAllowed(false).setCircularRedirectsAllowed(false).build());
        post.setEntity(new UrlEncodedFormEntity(params));
        response = http.execute(post);
        try {
          result = IOUtils.toString(response.getEntity().getContent(), "GB18030");
          matcher = PATTERN.matcher(result);
          if (matcher.find()) {
            this.sid = matcher.group(1);
          } else {
            matcher = PATTERN.matcher(response.getFirstHeader("Location").getValue());
            if (matcher.find()) {
              this.sid = matcher.group(1);
            } else {
              throw new SocialException("没有获取到sid");
            }
          }
        } catch (Exception e) {
          throw new SocialException("没有获取到sid");
        }
      }
      return this.sid;
    } catch (DecoderException e) {
      throw new SocialException(e);
    } catch (ClientProtocolException e) {
      throw new SocialException(e);
    } catch (IOException e) {
      throw new SocialException(e);
    }
  }
View Full Code Here

    try {
      HttpResponse response = http.execute(request);
      StatusLine statusLine = response.getStatusLine();
      if (statusLine == null || statusLine.getStatusCode() != HttpStatus.SC_OK
          || response.getEntity() == null) {
        throw new SocialException(String.valueOf(statusLine));
      }
      String result = IOUtils.toString(response.getEntity().getContent());
      request.releaseConnection();
      return new ValidationCode(result);
    } catch (ClientProtocolException e) {
      throw new SocialException(e);
    } catch (IOException e) {
      throw new SocialException(e);
    }
  }
View Full Code Here

    try {
      HttpResponse response = http.execute(request);
      StatusLine statusLine = response.getStatusLine();
      if (statusLine == null || statusLine.getStatusCode() != HttpStatus.SC_OK
          || response.getEntity() == null) {
        throw new SocialException(String.valueOf(statusLine));
      }
      byte[] result = IOUtils.toByteArray(response.getEntity().getContent());
      request.releaseConnection();
      return result;
    } catch (ClientProtocolException e) {
      throw new SocialException(e);
    } catch (IOException e) {
      throw new SocialException(e);
    }
  }
View Full Code Here

    try {
      HttpResponse response = http.execute(request);
      StatusLine statusLine = response.getStatusLine();
      if (statusLine == null || statusLine.getStatusCode() != HttpStatus.SC_OK
          || response.getEntity() == null) {
        throw new SocialException(String.valueOf(statusLine));
      }
      byte[] result = IOUtils.toByteArray(response.getEntity().getContent());
      request.releaseConnection();
      return result;
    } catch (ClientProtocolException e) {
      throw new SocialException(e);
    } catch (IOException e) {
      throw new SocialException(e);
    }
  }
View Full Code Here

      String json =
          post("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + accessToken,
              new StringEntity(request.toString()));
      return Result.parse(json, QRTicket.class);
    } catch (UnsupportedEncodingException e) {
      throw new SocialException(e);
    }
  }
View Full Code Here

      String json =
          post("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + accessToken,
              new StringEntity(message.toJSON(), "UTF-8"));
      return new Result<Boolean>(Error.parse(new JSONObject(json)));
    } catch (UnsupportedEncodingException e) {
      throw new SocialException(e);
    }
  }
View Full Code Here

  private void openLogin() throws ClientProtocolException, IOException, HttpException {
    String uri = "http://user.qzone.qq.com/" + qq + "/friendvisitor";
    HttpResponse response = http.execute(new HttpGet(uri));
    if (!Http.isRequestSuccess(response)) {
      throw new SocialException("Step 1, open login ui failed.");
    }

    Document doc = Jsoup.parse(Http.responseToString(response));
    loginUi = doc.select("#login_frame").get(0).attr("src");
    HttpGet request = new HttpGet(loginUi);
    request.addHeader(new BasicHeader("Referer", uri));
    response = http.execute(request);
    if (!Http.isRequestSuccess(response)) {
      throw new SocialException("Step 2, open login ui failed.");
    }

    doc = Jsoup.parse(Http.responseToString(response));
    Matcher matcher =
        Pattern.compile("login_sig\\s*:\\s*[\"']([^\"']+)[\"']").matcher(
            doc.select("script").get(0).html());
    if (!matcher.find()) {
      throw new SocialException("Step 3, login page isn't contain login_sig.");
    }
    loginSig = matcher.group(1);
  }
View Full Code Here

        new HttpGet("http://check.ptlogin2.qq.com/check?" + StringUtils.join(params, "&"));
    request.addHeader(new BasicHeader("Referer", loginUi));
    request.addHeader(new BasicHeader("Accept-Language", "zh-cn,zh"));
    HttpResponse response = http.execute(request);
    if (!Http.isRequestSuccess(response)) {
      throw new SocialException("Step 4, check if validation code failed.");
    }
    return new ValidationCode(Http.responseToString(response));
  }
View Full Code Here

        new HttpGet("http://captcha.qq.com/getimage?" + StringUtils.join(params, "&"));
    request.addHeader(new BasicHeader("Referer", loginUi));
    request.addHeader(new BasicHeader("Accept-Language", "zh-cn,zh"));
    HttpResponse response = http.execute(request);
    if (!Http.isRequestSuccess(response)) {
      throw new SocialException("Step 5, get validation code image failed.");
    }
    return IOUtils.toByteArray(response.getEntity().getContent());
  }
View Full Code Here

TOP

Related Classes of com.belerweb.social.exception.SocialException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.