提到http://www.2345.com/这个网址大家可能不会陌生,这是一家专门推广自己浏览器和软件的公司,同时也吸引了大量推广员以及电脑维修点帮他推广,安装他们的软件。
之前用python写过,2345自动签到,但是最近发现2345那帮人在登陆上做了手脚,每次都让你做个数学题,也就是验证码了,所以不能自动登陆了,也就没法签到了。
经过一下午的研究,当然是上个周末了…发现m.2345.com上面的登陆还是没有验证码的,而且会创建一个domain为*.2345.com的cookie,这样就能完成登陆啦,然后签到什么的都是浮云..嘿嘿
看代码:
import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import net.sf.json.JSONObject; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.ParseException; import org.apache.http.client.entity.UrlEncodedFormEntity; 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.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; import org.apache.http.util.EntityUtils; import org.apache.log4j.Logger; /** * * @ClassName: Jifen2345 * @Description: 2345自动签到 由于2345把登陆页面都加上了数字验证,但是发现 m.2345.com * 仍然不需要验证码即可创建domain为*.2345.com的cookie 2013-11-19 * @author kaedeen.com * @date 2013-11-19 下午9:00:08 * */ public class Jifen2345 { private static final Logger logger = Logger.getLogger(Jifen2345.class); private static DefaultHttpClient httpclient = null;// HttpClient对象 private static HttpResponse response = null; private static String mloginUrl = "http://m.2345.com/index.php?c=login&a=ajaxLogin";// 手机登陆请求地址 private static String checkinUrl = "http://jifen.2345.com/jifen/every_day_signature_new.php";// 签到请求地址 private String userName = "";// 用户名 private String passWord = "";// 密码明文 /** * 构造函数 * * @param userName * @param passWord */ public Jifen2345(String userName, String passWord) { this.userName = userName; this.passWord = passWord; } /** * 登陆 * * @return */ public boolean login(){ boolean flag = false; httpclient = new DefaultHttpClient(); // 设定cookie策略 HttpClientParams.setCookiePolicy(httpclient.getParams(),CookiePolicy.BROWSER_COMPATIBILITY); Listformparams =new ArrayList (); formparams.add(new BasicNameValuePair("username", userName)); formparams.add(new BasicNameValuePair("password", passWord)); HttpPost httppost = new HttpPost(mloginUrl); 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", "m.2345.com"); httppost.setHeader("Origin", "http://m.2345.com"); httppost.setHeader("Proxy-Connection", "keep-alive"); httppost.setHeader("Referer", "http://m.2345.com/index.php?c=login"); 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"); try { httppost.setEntity(new UrlEncodedFormEntity(formparams, HTTP.UTF_8)); //获取登陆应答内容 response = httpclient.execute(httppost); if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){ int code=getLoginCode(); if(0==code){ flag=true; }else{ logger.info(userName+"-用户名或密码有误!"); } }else{ logger.info(userName+"-2345登陆请求出错,post返回状态:"+response.getStatusLine().getStatusCode()); return false; } }catch (Exception e) { e.printStackTrace(); return false; } finally { httppost.abort(); } return flag; } /** * 每日签到 * @return */ public boolean everyDaySignature(){ boolean flag = false; HttpPost httppost = new HttpPost(checkinUrl); httppost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36"); httppost.addHeader("Host","jifen.2345.com"); httppost.addHeader("Referer","http://jifen.2345.com/index.php"); try { //获取登陆应答内容 response = httpclient.execute(httppost); if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){ HttpEntity httpEntity = response.getEntity(); String responseStr = EntityUtils.toString(httpEntity); //logger.info(userName+"-签到请求返回:"+responseStr); if(responseStr.startsWith("succ")){ flag=true; logger.info(userName+"-签到成功!:"+responseStr); } }else{ logger.info(userName+"-2345签到请求出错,post返回状态:"+response.getStatusLine().getStatusCode()); return false; } }catch (Exception e) { e.printStackTrace(); return false; } finally { httppost.abort(); } return flag; } /*返回字符串 * {"code":0,"msg":"u7528u6237u540du6216u5bc6u7801u4e0du5bf9"} */ private int getLoginCode(){ int code=2; HttpEntity httpEntity = response.getEntity(); String responseJsonStr = ""; try { responseJsonStr = EntityUtils.toString(httpEntity); //logger.info("responseJsonStr---"+responseJsonStr); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }//取出应答字符串 Map map = JSONObject.fromObject(responseJsonStr); code=(Integer) map.get("code"); logger.info(userName+"-捕获登陆返回code:"+code); return code; } }
一点点牢骚:
其实去年就写了2345自动签到的程序,也挂在sae上面签到了一年了吧,因为自己不装机也不坑害别人装他们的浏览器或者软件,只是靠签到,所以一直收入甚微,到现在估计折合软妹币也就49元左右的样子…
话说回来,写这些签到模拟登陆的程序都是个人兴趣,不指望用来赚钱,自己也真心不会赚钱,google adsense都“莫名其妙”被封了,所以基本没啥额外收入了。
大家看代码时候有啥问题,请您留言,我看到会解答。如果伸手要直接可运行程序什么什么的,那个只能给好朋友,所有代码都在这里你都不想研究,我也帮不上你…
我会把代码尽快放到github或者其他上面,敬请关注。