日期:2014-05-18 浏览次数:20701 次
package com.agileeagle.app.invite.importlist.email; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.NameValuePair; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.filters.AndFilter; import org.htmlparser.filters.HasAttributeFilter; import org.htmlparser.filters.TagNameFilter; import org.htmlparser.util.NodeList; import org.htmlparser.visitors.TagFindingVisitor; import com.agileeagle.app.invite.importlist.Contact; import com.agileeagle.app.invite.importlist.exception.AuthorMatchException; import com.agileeagle.app.invite.importlist.exception.ContactsException; import com.agileeagle.core.config.CharsetConfig; /** * QQ好友列表 * @author Administrator * */ public class QQImporter extends EmailImporter { private String beforeLoginUrl = "https://mail.qq.com/cgi-bin/loginpage?"; private String loginImgUrl = "https://mail.qq.com/cgi-bin/getverifyimage?aid=23000101&f=html&ck=1&0.4268505945413007"; private final static String EXEC_JS = "var StartTime=(new Date()).valueOf();var PublicKey = \"CF87D7B4C864F4842F1D337491A48FFF54B73A17300E8E42FA365420393AC0346AE55D8AFAD975DFA175FAF0106CBA81AF1DDE4ACEC284DAC6ED9A0D8FEB1CC070733C58213EFFED46529C54CEA06D774E3CC7E073346AEBD6C66FC973F299EB74738E400B22B1E7CDC54E71AED059D228DFEB5B29C530FF341502AE56DDCFE9\";var RSA = new RSAKey();RSA.setPublic(PublicKey, \"10001\");"; private static String AUTHOR_JS = null; static{ try { StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(new InputStreamReader(QQImporter.class.getClassLoader().getResourceAsStream("safeauth.js"),CharsetConfig.UTF_8)); String line = null; while((line=br.readLine())!=null){ sb.append(line).append("\n"); } AUTHOR_JS = sb.deleteCharAt(sb.length()-1).toString(); br.close(); } catch (Exception e) { e.printStackTrace(); } } private String urlHead = null; private String sid = null; private String targetUrl = null; // 好友联系人列表的URL private String contactsUrl = "addr_listall?grpid=1000&isqqgroup=1&sid="; /** * 构造函数 * * @param email * @param password */ public QQImporter(String email, String password) { super(email, password,"GBK"); } /** * 登录Gmail邮箱 * * @throws ContactsException */ public void doLogin() throws ContactsException { try { String content = doGet(beforeLoginUrl); ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); engine.eval(AUTHOR_JS); engine.eval(EXEC_JS); Object startTime = engine.get("StartTime"); String ts = getInputValue("name=\"ts\"", content); StringBuilder pp = new StringBuilder(); for(int i=0;i<password.length();i++){ pp.append("0"); } StringBuilder encrypt = new StringBuilder(); encrypt.append("var Res = RSA.encrypt('").append(password).append("'+'\\n'+'").append(ts).append("'+'\\n');if (Res){Res = hex2b64(Res);}"); engine.eval(encrypt.toString()); Object