如何登陆360,并每日自动签到
这次的难点主要集中在登陆这里了,开始抓包发现360登陆验证很麻烦,但是后来发现一个简单的方法。
因为我安装了360安全卫士,发现点击那个金币的按钮能直接验证登陆,哈哈~所以httpclient直接get这个url就能创建cookie完成登陆了~
上面说的不明白,看图:

 import java.io.IOException;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import net.sf.json.JSONObject; import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger; import com.kae.common.CustomerHttpClient;
import com.kae.common.DummyRedirectHandler; /**
*
* @ClassName: Jifen360
* @Description: 360积分
* @author kaedeen.com
* @date 2013-11-22 下午9:28:24
*
*/ public class Jifen360 { private static final Logger logger = Logger.getLogger(Jifen360.class); private static DefaultHttpClient httpclient = null;// HttpClient对象 private static HttpResponse response = null; private String url = ""; public Jifen360(String url) {
this.url = url;
} /**
* 签到
*
* @return
*/
@SuppressWarnings({ "deprecation","rawtypes" })
public boolean signIn() {
boolean flag = false; httpclient = new DefaultHttpClient();
// 设定cookie策略
HttpClientParams.setCookiePolicy(httpclient.getParams(),
CookiePolicy.BROWSER_COMPATIBILITY); httpclient.setRedirectHandler(new DummyRedirectHandler()); HttpGet httpGet = new HttpGet(url); try {
response = httpclient.execute(httpGet);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
logger.error("Jifen360 signIn ClientProtocolException:"+e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("Jifen360 signIn IOException:"+e.toString());
} finally {
httpGet.abort();
} String token = getToken(); // 请求签到链接
String signInUrl="http://jifen.360.cn/safe/ajax_signin.html?token="+token; HttpPost httppost = new HttpPost(signInUrl);
httppost.setHeader("Accept", "*/*");
httppost.setHeader("Accept-Language","zh-CN,zh;q=0.8,en;q=0.6,ja;q=0.4,zh-TW;q=0.2");
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httppost.setHeader("Host", "jifen.360.cn");
httppost.setHeader("Origin", "http://jifen.360.cn");
httppost.setHeader("Proxy-Connection", "keep-alive");
httppost.setHeader("Referer", "http://jifen.360.cn/safe?src=safe");
httppost.setHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36");
httppost.setHeader("X-Requested-With", "XMLHttpRequest"); try {
//获取签到应答内容
response = httpclient.execute(httppost);
HttpEntity httpEntity = response.getEntity();
String responseJsonStr = EntityUtils.toString(httpEntity); //请求示例
//{"errno":0,"errmsg":"","data":{"dayslen":1,"score":2,"signin_count":608904}} 成功
//{"errno":1,"errmsg":"\u60a8\u4eca\u5929\u5df2\u7ecf\u7b7e\u8fc7\u5230\u4e86~","data":""} 失败 logger.info("Jifen360 请求签到链接 responseJsonStr:"+responseJsonStr); Map map = JSONObject.fromObject(responseJsonStr);
int code=(Integer)map.get("errno"); if(0==code){
flag=true;
logger.info("Jifen360 签到 成功!");
}else{
logger.info("Jifen360 今天已经签到了!");
} }catch (Exception e) {
logger.error("Jifen360 signIn 请求签到链接 失败:"+e.toString());
return false;
} finally {
httppost.abort();
} return flag;
} /**
* 获取302跳转的
*
* @return
*/
private String getRedirectLocation() {
Header locationHeader = response.getFirstHeader("Location");
if (locationHeader == null) {
return null;
}
return locationHeader.getValue();
} /**
* 获取360 token
*
* @return
*/
private String getToken() { String redirectUrl = getRedirectLocation(); String token = ""; String responseBody = CustomerHttpClient.get(httpclient, redirectUrl);
// System.out.println(responseBody); Pattern pattern1 = Pattern.compile("token\":\"(.*)\",\"mall_tpl");
Matcher m1 = pattern1.matcher(responseBody);
if (m1.find()) {
token = m1.group(1);
logger.info("Jifen360 360 token:"+token);
} else {
logger.error("Jifen360 360 获取360 token失败!");
} return token;
} }

360每日自动签到,领取积分 (java httpclient4.x)-LMLPHP

05-11 10:54