锁定老帖子 主题:山寨开心网停车外挂开发...
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-01-10
最后修改:2009-02-25
前端时间玩了一下开心网,开心网里面有个争车位还蛮有意思的
email tbill@sina.com
CookieStore cookieStore = null; try { DefaultHttpClient httpclient = new DefaultHttpClient(); //登陆 //这里Constants是我自定义的一个常量类 HttpPost httpost = new HttpPost(Constants.LOGINURL); //登陆的参数 List<NameValuePair> nvps = new ArrayList<NameValuePair>(); //EMAIL nvps.add(new BasicNameValuePair(Constants.EMAIL, email)); //密码 nvps.add(new BasicNameValuePair(Constants.PASSWORD, password)); //URL nvps.add(new BasicNameValuePair(Constants.URL, "/")); httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); //执行登陆 HttpResponse response = httpclient.execute(httpost); //获取HTTP响应头中的Set-Cookie Header header = response.getFirstHeader("Set-Cookie"); HeaderElement[] elements = header.getElements(); if (elements != null) { for (HeaderElement element : elements) { if ("_user".equals(element.getName())) { // System.out.println(element.getValue()); if ("deleted".equals(element.getValue())) { System.out.println("登陆失败"); } else { System.out.println("登陆成功"); //获取cookies cookieStore = httpclient.getCookieStore(); } break; } } } return cookieStore;
2) 登陆争车位 DefaultHttpClient httpclient = new DefaultHttpClient(); //登陆 HttpPost httpost = new HttpPost(FRIENDPARK); //登陆的参数 List<NameValuePair> nvps = new ArrayList<NameValuePair>(); //EMAIL nvps.add(new BasicNameValuePair("_", null)); //好友ID nvps.add(new BasicNameValuePair("puid", puid)); //验证字符串 nvps.add(new BasicNameValuePair("verify", verify)); httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); //设置COOKIES HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); //进入好友车位 ResponseHandler<String> responseHandler = new BasicResponseHandler(); //获取好友数据 String responseBody = httpclient.execute(httpost, responseHandler, localContext); JSONObject friendJson = new JSONObject(responseBody); // JSONArray parks = friendJson.getJSONArray("parking"); //这里CommonFunction是我自定义的一个解析json数组的一个工具类 List list = CommonFunction.parseJsonArray(friendJson.getString("parking"), Parking.class);
b) 如果是免费车位,停车,当然还要判断该车位上是否有汽车 Integer parkid = Integer.parseInt(parking.getParkid()); //flag=1是免费车位,flag=0不是免费车位 int flag = (parkid >> 16) & 0xff; 停车: DefaultHttpClient httpclient = new DefaultHttpClient(); //停车 HttpPost httpost = new HttpPost(PARKINGURL); //停车的参数 List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("_", null)); nvps.add(new BasicNameValuePair("acc", parkEntity.getAcc())); nvps.add(new BasicNameValuePair("carid", carid)); nvps.add(new BasicNameValuePair("first_fee_parking", "0")); nvps.add(new BasicNameValuePair("neighbor", neighbor)); nvps.add(new BasicNameValuePair("park_uid", parkuid)); nvps.add(new BasicNameValuePair("parkid", parking.getParkid())); nvps.add(new BasicNameValuePair("verify", parkEntity.getVerify())); httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); //设置COOKIES HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, parkEntity.getCookieStore()); ResponseHandler<String> responseHandler = new BasicResponseHandler(); //获取停车信息 String responseBody = httpclient.execute(httpost, responseHandler, localContext); System.out.println(responseBody); Map map = CommonFunction.parseJSON(responseBody); //获取停车结果 res = Integer.parseInt((String) map.get("errno"));
verify这个参数也需要从首页上提取
/** * 调用自动生成的ACC方法 * @param script * @return */ public static String invokeAccScript(String script) { String acc = null; try { StringBuilder builder = new StringBuilder(); BufferedReader reader1 = new BufferedReader(new StringReader(script)); reader1.readLine(); while ((acc = reader1.readLine()) != null) { if (acc.startsWith("function notice()")) { break; } else { builder.append(acc); } } reader1.close(); ScriptEngineManager m = new ScriptEngineManager(); ScriptEngine engine = m.getEngineByName("javascript"); if (engine != null) { engine.eval(builder.toString()); Invocable invocableEngine = (Invocable) engine; //调用acc方法获取验证码 acc = invocableEngine.invokeFunction("acc").toString(); } } catch (Exception e) { e.printStackTrace(); } return acc; }
今天把源代码加上。。。 写得不好的地方请拍砖 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-01-10
开发出来了吗?
|
|
返回顶楼 | |
发表时间:2009-01-10
java.lang.Object 写道 开发出来了吗?
开发出来了啊 不过就一个停车位的功能 哈哈! |
|
返回顶楼 | |
发表时间:2009-02-01
上传上来试用一下啊
|
|
返回顶楼 | |
发表时间:2009-02-02
就是,分享一下咯……或者开源一下,大家一起完善开心网外挂~
|
|
返回顶楼 | |
发表时间:2009-02-17
恩 思路基本一致 但是注意他的那个客户端的动态token的定位问题,记得去年做这个东西的时候kaixin001还是简单的post就可以了 然后又进化了一次 最后采用了这种客户端动态token的方式。
|
|
返回顶楼 | |
发表时间:2009-02-17
Firefox + GreaseMonkey + UserScript 搞定webgame外挂
|
|
返回顶楼 | |
发表时间:2009-02-18
very nice~
|
|
返回顶楼 | |
发表时间:2009-02-18
现在好多基于flash,flex的webgame。开发这样的游戏外挂貌似要更加麻烦点吧。
|
|
返回顶楼 | |
发表时间:2009-02-20
恩,学了不少东西
|
|
返回顶楼 | |