邀请QQ好友-QQ联系人导入(上)
2009-09-06 00:00:00 来源:WEB开发网-------VerifyCode.java--------------
Java代码
package qq;
import org.apache.commons.httpclient.Cookie;
public class VerifyCode {
private Cookie verifySession;
private byte[] data;//verify code image
public VerifyCode(){}
public VerifyCode(Cookie verifySession, byte[] data){
this.verifySession = verifySession;
this.data = data;
}
public Cookie getVerifySession() {
return verifySession;
}
public void setVerifySession(Cookie verifySession) {
this.verifySession = verifySession;
}
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
}
---------QQUtil.java-------------------
Java代码
package qq;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class QQUtil {
public static Pattern sidPattern = Pattern.compile("sid=(.*?)\";");
public static Pattern contactPattern = Pattern.compile("<.*?key=\"(.*?)\" addr=\"(.*?)\".*?>(.*?)</span>");
public static Pattern publicKeyPattern = Pattern.compile("PublicKey = \"(.*?)\"");
public static Pattern tsPattern = Pattern.compile("PublicTs=\"(.*?)\"");
public static Pattern domainPattern = Pattern.compile("action=\"(.*?\\.qq\\.com)");
public static Pattern errTypePattern = Pattern.compile("\"errtype=(.?)\"");
public static String paser(String body,Pattern pattern) {
String publicKey = null;
Matcher matcher = pattern.matcher(body);
if (matcher.find()) {
publicKey = matcher.group(1);
}
return publicKey;
}
public static List<QQContact> parserQQContects(String contactsHtml) {
List<QQContact> list = new ArrayList<QQContact>();
Matcher allMatcher = contactPattern.matcher(contactsHtml);
while(allMatcher.find()){
String qq = allMatcher.group(1);
String email = allMatcher.group(2);
String name=allMatcher.group(3).replace(" ", "");
list.add(new QQContact(qq,email,name));
}
return list;
}
}
更多精彩
赞助商链接