这边只列举出163的 其他的可以联系本人购买价格面议 可免费升级。
需要的 给我发邮件: sl514@163.com
package com.d1xn.invite.mailImportor.mailImporter;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.NameValuePair;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.message.BasicNameValuePair;
import org.apache.log4j.Logger;
import com.d1xn.core.config.CoreErrorCode;
import com.d1xn.core.util.IOUtil;
import com.d1xn.invite.config.InviteErrorCode;
import com.d1xn.invite.mailImportor.common.ContactImpl;
import com.d1xn.invite.mailImportor.common.ContactListImporterImpl;
import com.d1xn.invite.mailImportor.user.Contact;
import com.d1xn.invite.mailImportor.util.StringUtil;
/**
* 网易163邮箱导入对象
*
* @author shaliang
* @blog www.ij2ee.com
*
*/
public class Mail163Importer extends ContactListImporterImpl {
@Override
/**
* 登录
*/
protected int login(DefaultHttpClient client) throws Exception {
//log.info(this.getemail());
NameValuePair data[] = { new BasicNameValuePair(".verifycookie", "1"),
new BasicNameValuePair("style", "35"),
new BasicNameValuePair("product", "mail163"),
new BasicNameValuePair("username", this.getUsername()),
new BasicNameValuePair("password", this.getPassword()),
new BasicNameValuePair("selType=", "jy"),
new BasicNameValuePair("remUser", "on"),
new BasicNameValuePair("secure", "on") };
long time = System.currentTimeMillis();
BasicClientCookie cookie = new BasicClientCookie("163_LOGIN",
(new StringBuilder("T")).append(time).append("/").append(
time - 16L).append("/").append(time).toString());
client.getCookieStore().addCookie(cookie);
log.info(cookie);
String loginPageUrl = getLoginURL() + "&d="
+ System.currentTimeMillis();
log.info("Requesting login page");
//发送post请求 获取响应字符串
String content = readInputStream(doPost(client, loginPageUrl, data, ""),null);
if (content.contains("window.location.replace")) {
log.info("redirecting");
} else {
log
.info("Login failed, username or password do not match please check your name&password");
return CoreErrorCode.ACCOUNT_OR_PASSWORD_ERROR;
}
String reUrl = content.substring(content.indexOf("window.location.replace(\"") + 25);
reUrl = reUrl.substring(0, reUrl.indexOf("\")"));
InputStream is = doGet(client, reUrl, null);
content = readInputStream(is,null);
String sessId = null;
if (content.contains("index.jsp?sid=")) {
String regex = "index.jsp\\?sid=([^\\\"]+)";
sessId = StringUtil.getByRegex(regex, 1, content);
tempSessId = sessId;
}
return InviteErrorCode.INVITE_OPERATE_SUCCESS;
}
/**
* 从指定流中解析出联系人集合
*
* @param is
* 指定的流对象
* @return 解析后得到的联系人集合
*/
@Override
protected List<Contact> parseContacts(InputStream is) throws Exception {
// TODO Auto-generated method stub
List<Contact> contactList = new ArrayList<Contact>();
String line = readInputStream(is,"utf-8");
is.close();
System.err.println(line);
String aa = "<div class=\"gTitleSub\"><div align=\"left\"><b class=\"mTT\">([^<]+)</b></div><div class=\"Extra\"></div></div><table class=\"gTable\"><tr id=\"tr_base_0\" style=\"\"><th>[^<]+</th><td>([^<]+)</td></tr>";
Pattern p = Pattern.compile(aa);
Matcher m = p.matcher(line);
int groupNum = 0;
int firstIndex = 0;
while(m.find(firstIndex))
{
String name = m.group(1);
String email = m.group(2);
contactList.add(new ContactImpl(name,email));
firstIndex = m.end();
groupNum++;
}
return contactList;
}
private Logger log = Logger.getLogger(this.getClass());
private String tempSessId = "";
private String loginURL;
private String contactListURL;
public Mail163Importer() {
}
public Mail163Importer(String username, String password) {
super(username, password);
}
public void setLoginInfo(String email, String password) {
super.setLoginInfo(email, password);
}
public void setLoginURL(String loginURL) {
this.loginURL = loginURL;
}
public void setContactListURL(String contactListURL) {
this.contactListURL = contactListURL + this.tempSessId;
}
public void setTempSessId(String tempSessId) {
this.tempSessId = tempSessId;
}
@Override
public String getContactListURL() {
return this.contactListURL + tempSessId;
}
@Override
public String getLoginURL() {
return this.loginURL;
}
}
项目运行结果: