HttpClient4模拟登录腾讯微博及分享功能
2012-07-01 21:02
555 查看
package com.wolf.httpclient;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
public class TencentClient {
/**
* @param args
*/
public static void main(String[] args) {
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(
HttpConnectionParams.CONNECTION_TIMEOUT, 5000);
try {
/*********************获取验证码***********************/
HttpGet get = new HttpGet(
"http://ptlogin2.qq.com/check?uin="+用户名或QQ号+"&appid=46000101&r=0.37908964480776913");
HttpResponse response = client.execute(get);
String entity = EntityUtils.toString(response.getEntity());
String[] checkNum = entity.substring(entity.indexOf("(") + 1,
entity.lastIndexOf(")")).replace("'", "").split(",");
System.out.println(checkNum[1]);
String pass="";
/******************** *加密密码***************************/
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("javascript");
String jsFileName = "src/md5.js"; //指定md5加密文件
// 读取js文件
FileReader reader;
reader = new FileReader(jsFileName);
engine.eval(reader);
if (engine instanceof Invocable) {
Invocable invoke = (Invocable) engine;
// 调用preprocess方法,并传入两个参数密码和验证码
pass = (String)invoke.invokeFunction("preprocess", 密码,checkNum[1]);
System.out.println("c = " + pass);
}
reader.close();
/*************************登录****************************/
get=new HttpGet("http://ptlogin2.qq.com/login?ptlang=2052&u=用户名或QQ号&p="+pass+"&verifycode="+checkNum[1]+"&low_login_enable=1&low_login_hour=720&aid=46000101&u1=http%3A%2F%2Ft.qq.com&ptredirect=1&h=1&from_ui=1&dumy=&fp=loginerroralert&action=4-13-11101&dummy=");
System.out.println(get.getURI());
response = client.execute(get);
entity = EntityUtils.toString(response.getEntity());
System.out.println(entity);
/*************************分享*************************/
HttpPost post = new HttpPost("http://radio.t.qq.com/publish.php");
//这句很重要
post.addHeader("Referer","http://radio.t.qq.com/share.php?title=%E4%B9%8C%E9%B2%81%E6%9C%A8%E9%BD%90%E5%B8%82%E5%A4%A7%E9%A3%8E%E8%87%B473%E4%BA%BA%E5%8F%97%E4%BC%A4%203%E4%BA%BA%E6%AD%BB%E4%BA%A1(%E5%9B%BE)&url=http://news.qq.com/a/20120331/000027.htm&pref=qqcom.dp.tmblog&source=qqnews");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("content", "乌鲁木齐市大风致73人受伤 3人死亡(图) http://news.qq.com/a/20120331/000027.htm (分享自 @腾讯新闻 )"));
nvps.add(new BasicNameValuePair("countType", ""));
nvps.add(new BasicNameValuePair("pic", ""));
nvps.add(new BasicNameValuePair("source", "1000001"));
nvps.add(new BasicNameValuePair("sourcepic", "http://img1.gtimg.com/news/pics/hv1/125/130/1010/65708525.jpg"));
nvps.add(new BasicNameValuePair("viewModel", "0"));
nvps.add(new BasicNameValuePair("wizardpref","qqcom.dp.tmblog"));
nvps.add(new BasicNameValuePair("wizardurl", "http://news.qq.com/a/20120331/000027.htm"));
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = client.execute(post);
entity = EntityUtils.toString(response.getEntity());
System.out.println(entity);
} catch (Exception e) {
// TODO: handle exception
}
}
}
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
public class TencentClient {
/**
* @param args
*/
public static void main(String[] args) {
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(
HttpConnectionParams.CONNECTION_TIMEOUT, 5000);
try {
/*********************获取验证码***********************/
HttpGet get = new HttpGet(
"http://ptlogin2.qq.com/check?uin="+用户名或QQ号+"&appid=46000101&r=0.37908964480776913");
HttpResponse response = client.execute(get);
String entity = EntityUtils.toString(response.getEntity());
String[] checkNum = entity.substring(entity.indexOf("(") + 1,
entity.lastIndexOf(")")).replace("'", "").split(",");
System.out.println(checkNum[1]);
String pass="";
/******************** *加密密码***************************/
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("javascript");
String jsFileName = "src/md5.js"; //指定md5加密文件
// 读取js文件
FileReader reader;
reader = new FileReader(jsFileName);
engine.eval(reader);
if (engine instanceof Invocable) {
Invocable invoke = (Invocable) engine;
// 调用preprocess方法,并传入两个参数密码和验证码
pass = (String)invoke.invokeFunction("preprocess", 密码,checkNum[1]);
System.out.println("c = " + pass);
}
reader.close();
/*************************登录****************************/
get=new HttpGet("http://ptlogin2.qq.com/login?ptlang=2052&u=用户名或QQ号&p="+pass+"&verifycode="+checkNum[1]+"&low_login_enable=1&low_login_hour=720&aid=46000101&u1=http%3A%2F%2Ft.qq.com&ptredirect=1&h=1&from_ui=1&dumy=&fp=loginerroralert&action=4-13-11101&dummy=");
System.out.println(get.getURI());
response = client.execute(get);
entity = EntityUtils.toString(response.getEntity());
System.out.println(entity);
/*************************分享*************************/
HttpPost post = new HttpPost("http://radio.t.qq.com/publish.php");
//这句很重要
post.addHeader("Referer","http://radio.t.qq.com/share.php?title=%E4%B9%8C%E9%B2%81%E6%9C%A8%E9%BD%90%E5%B8%82%E5%A4%A7%E9%A3%8E%E8%87%B473%E4%BA%BA%E5%8F%97%E4%BC%A4%203%E4%BA%BA%E6%AD%BB%E4%BA%A1(%E5%9B%BE)&url=http://news.qq.com/a/20120331/000027.htm&pref=qqcom.dp.tmblog&source=qqnews");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("content", "乌鲁木齐市大风致73人受伤 3人死亡(图) http://news.qq.com/a/20120331/000027.htm (分享自 @腾讯新闻 )"));
nvps.add(new BasicNameValuePair("countType", ""));
nvps.add(new BasicNameValuePair("pic", ""));
nvps.add(new BasicNameValuePair("source", "1000001"));
nvps.add(new BasicNameValuePair("sourcepic", "http://img1.gtimg.com/news/pics/hv1/125/130/1010/65708525.jpg"));
nvps.add(new BasicNameValuePair("viewModel", "0"));
nvps.add(new BasicNameValuePair("wizardpref","qqcom.dp.tmblog"));
nvps.add(new BasicNameValuePair("wizardurl", "http://news.qq.com/a/20120331/000027.htm"));
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = client.execute(post);
entity = EntityUtils.toString(response.getEntity());
System.out.println(entity);
} catch (Exception e) {
// TODO: handle exception
}
}
}
相关文章推荐
- HttpClient4模拟登录腾讯微博及分享功能
- C# 实现模拟登录功能,实现公共类分享。
- C# 实现模拟登录功能,实现公共类分享。
- 实战新浪微博、腾讯微博的分享功能
- 模拟用户登录功能
- IOS项目集成ShareSDK实现第三方登录、分享、关注等功能(备用)
- IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。
- ShareSDK实现授权登录和分享功能
- Android应用同时实现微信分享和微信登录功能
- Android开发 QQ sso登录和分享到QQ好友功能,调用本地QQ客户端
- 有奖试读 使用share SDK实现腾讯微博授权登录分享(1.x版本)
- shell脚本实现ssh自动登录功能分享
- python模拟登录百度代码分享(获取百度贴吧等级)
- [置顶] React Native实现第三方分享、登录功能(Android,IOS双平台)
- IOS项目集成ShareSDK实现第三方登录、分享、关注等功能
- Android开发 QQ sso登录和分享到QQ好友功能,调用本地QQ客户端
- android 实现QQ第三方登录,分享功能
- 模拟用户登录的功能
- 实战新浪微博、腾讯微博的分享功能
- iOS学习笔记55- iOS项目集成ShareSDK实现第三方登录、分享、关注等功能。