校友QQ农场SNSGAME是基于http协议的,因此只要通过工具软件截取http数据包,从而进一步进行分析提交和接收到的数据含义,然后再模拟一个flash client和服务器打交道即可。
为了实现以上目标,下载安装截获tcp/ip数据包的工具软件ethereal,安装好以后,登陆QQ进入农场,然后开启ethereal软件开始截获数据包,然后在农场里点刷新好朋友列表按钮,然后去ethereal里看看截获到的数据包,发现读取好朋友列表的url地址是:
http://happyfarm.qzone.qq.com/api.php?mod=friend
需要的参数有:login_time 、skey、uin 三个
知道这个地址以后,可以用apache httpclient模拟一个flash client,具体代码如下:
String login_time = ConfigProperties.getProperty("login_time");
String skey = ConfigProperties.getProperty("skey");
String _s_ = ConfigProperties.getProperty("_s_");
String uin = ConfigProperties.getProperty("uin");
HttpClient hc = new HttpClient();
// 创建GET方法的实例
GetMethod getMethod = new GetMethod(url);
//
getMethod.addRequestHeader("Accept", "*/*");
getMethod
.addRequestHeader(
"User-Agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; 360SE)");
getMethod.addRequestHeader("Accept-Encoding", "gzip, deflate");
getMethod.addRequestHeader("Accept-Language", "zh-CN");
getMethod.addRequestHeader("Connection", "Keep-Alive");
getMethod.addRequestHeader("Pragma", "no-cache");
hc.getState().clearCookies();
//
String cookies = "1" + "; _s_=" + _s_ + "; uin=" + uin + "; skey="
+ skey + "; login_time=" + login_time;
hc.getState().addCookie(
new Cookie("happyfarm.qzone.qq.com", "jump", cookies, "/",
new Date(2011, 12, 8), false));
// 执行getMethod
int statusCode = hc.executeMethod(getMethod);
//
String result = getMethod.getResponseBodyAsString();
按照这种方法,可以找到获取某个好朋友农场信息的url地址是:
http://nc.qzone.qq.com/cgi-bin/cgi_farm_index?mod=user&act=run&ownerId=
偸某个好朋友某块或多块地的url地址是:
http://nc.qzone.qq.com/cgi-bin/cgi_farm_steal?mod=farmlandstatus&act=scrounge
ok,这些都搞定了,另外盗菜的 url地址需要提交一个参数farmKey,这个生成方法有点难度,具体方法为:
int curTime = (int) (System.currentTimeMillis() / 1000L);
String s = "sdoit78sdopig7w34057";
in
t yushu = curTime % 10;
s = s.substring(yushu, 20);
String farmKey = com.sourceware.util.StringUtil
.getMD5(curTime + s);
另外需要分析一下服务器返回的数据包格式,目前看到的都是 json格式,
比如得到好朋友列表的数据为:
[{"userId":1905432,"userName":"\u6c38\u8fdc\u7684\u9ed1","headPic":"http:\/\/qlogo2.store.qq.com\/qzonelogo\/1265877\/1\/1242884728","yellowlevel":0,"yellowstatus":0,"exp":7776,"money":38961,"pf":0},{"userId":159805,"userName":"\u8f7b\u63cf\u6de1\u5199","headPic":"http:\/\/imgcache.qq.com\/qzone_v4\/client\/userinfo_icon\/5001.gif","yellowlevel":0,"yellowstatus":0,"exp":20332,"money":22665,"pf":0},{"userId":65178,"userName":"Air-F","headPic 后面省略...
如果是用java开发的话可以用json-lib包来解析。
另外根据返回的错误提示语整理如下:
如果返回{"code":0,"direction":"这块地没东西可摘的!","farmlandIndex":2,"fkey":"8297832f9f305bd1ad2d083c35148d815069b5c61da3382c0119b74f65b8e42e6d597313b9101acb","poptype":1}
应该是这块地已经成熟,且被人摘光了(成熟的地都有一个产量,剩余数,最小的剩余数《通过这个可以得到最多可以被偸几个》)。
如果返回的是{"code":0,"direction":"获取农田信息失败","fkey":"e3c2806e13df1092281157971b0f9466dcfbe7433a368f4d2398b0721398add7afc8c76f889555d5","poptype":0}
那么应该是这块地还没成熟就去偸了;或者已经被主人收割了;或者这块地什么都没种;
如果返回的是:{"code":0,"direction":"做人不能贪得无厌!","farmlandIndex":1,"fkey":"2848bb16cb28e1929822cb716b0e87292864ea9068ebe95b5d6d51580fb4b13718e3c2787af58294","poptype":1},{"code":0,"direction":"做人不能贪得无厌!","farmlandIndex":2,"poptype":1}
那说明您已经偸过了还要去偸;