QQ农场源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

QQ农场源代码
//已知BUG
//Preprocess 函数所得出的密码有些错误,比如:QQ密码为16位,有各种字符的,就可能登录失败// 可能是Delphi MD5算法的原因,我用VC2005来试过,没有错误.由于工作太忙
// 没有时间细细检查,还在麻烦大家试试
}
unit WebQQFunction;
interface
uses
Windows, SysUtils, Classes, StdCtrls, IdBaseComponent, IdComponent, StrUtils, ExtCtrls, IdTCPConnection, IdTCPClient, IdHTTP, jpeg, IdAuthentication, IdHash, IdHashMessageDigest, PublicFunctions, IniFiles, Forms, ComCtrls, SHDocVw, Dialogs, V ariants, DateUtils;
const
//QQ校友农场
C;
//QQ空间农场
C;
//登录用的字符串
C;
C+
'login&fp=&h=1&ptredirect=1&ptlang=0&from_ui=1&du my=1';
//操作农场时,IdHTTP Referer 的值通过GetFlaseV ersion得到IdHTTP Referer的全部字串
C;
//FarmKey的形式
C;
//读取好友列表
C;
//自己ID,名字,时间,对方名称,farmKey
C;
//Cookie的组成
C;
//升一级加多少经验
CONST_OneLevelNum = 200;
//取FarmKey时,时间延后多少秒
Const_DelayFarmTime = 10;
type
//背包类型0仓库1商店2包裹
TBagsType = (farm_Warehouse, farm_Goods, farm_Bag);
//动作类型0偷取1杀虫2浇水3除草4收获
// 5松土6种植7全部卖出8购买种子
// 9查看消息10所有动作(在PostAction中没有实现义意,不作操作)
TActionType =(Action_scrounge, Action_spraying, Action_water, Action_clearWeed,
Action_harvest, Action_scarify, Action_planting, Action_Sale, Action_SaleAll,
Action_Buy, Action_getAllInfo, Action_ALL_OPP);
var
QQ_Cookie, V erifySession, farmKey, ConnHost,
Cookie_pt2gguin, Cookie_uin, Cookie_skey, Cookie_ptcz,
Cookie_pvid, Cookie_name, FlaseVersion: string;
farmTime, Cookie_pst: int64;
//服务器时间本地时间本地时间与服务器的时间差
QQ_ServerTime, Loc_ServerTime, DelayedDpikeInt : integer;
//将本地时间转成QQ服务器时间
function DateTimeToServerTime(aDateTime: TDateTime): integer;
function Preprocess(aPassWord, aV erifyCode:string):string;
//取得Flash版本通过GetFlaseV ersion得到IdHTTP Referer的全部字串
procedure GetFlaseV ersion(var aStr: string);
//取得验证码
function GetV erifyPic(aIdHTTP:TIdHTTP; var aImage: TImage): boolean;
//将汉字转换为unicode码
function AnsiT oUnicode(aSubWideChar: PWideChar):string;
//将unicode码转换为汉字
function UnicodeT oAnsi(aSubUnicode: string):string;
//提取字符串
function SubString(aInputStr, aStr_L, aStr_R:string):string;
function HashStr2BinStr(Hash: string):string;
function Fmd5(str: string):string;
//以Web形式登录QQ
function LoginQQ(aIdHTTP: TIdHTTP; aUserNameStr, aPasswordStr, aV erifyStr: string; var aWebStr: string): Boolean;
//登录QQ校友社区
function LoginQQxiaoyou(aIdHTTP: TIdHTTP): Boolean;
//取自己农场数据
function GetMyFarmLandDB(aIdHTTP: TIdHTTP; var aWebStr: string): Boolean;
//取好友列表数据
function GetFriendsListDB(aIdHTTP: TIdHTTP; var aWebStr: string): Boolean;
//取好友农场数据
function GetFriendFarmLandDB(aIdHTTP: TIdHTTP; aUserID: integer; var aWebStr: string): Boolean;
//计算等级返回等级
function ResultLevel(aSumExp:integer; var aNowExp, aOutLevelMaxExp: integer): integer;
//分析仓库商店背包数据aType 0仓库1商店2背包
function PostBagsBD(aIdHTTP:TIdHTTP; var aWebStr: string; aType: TBagsType): boolean;
//动作类型0偷取1杀虫2浇水3除草4收获
// 5松土6种植7全部卖出8购买种子
// 9查看消息10所有动作(在PostAction中没有实现义意,不作操作)
//
//aActionType动作类型是种植\卖出\购买种子还是做什么在此赋值
//aOwnerId是自己的UserID 必须为自己的UserID
//aPlace为地块的序号,从0开始不用时可为0
//aSeedID 为作物\种子的aID 种植\卖出\购买种子时用到不用时可为0
function PostAction(aIdHTTP: TIdHTTP; var aWebStr: string; aActionType: TActionType;
aOwnerId, aPlace, aSeedID: integer): boolean;
//取得farmKey
function GetfarmKey(aInputTimeInt: Int64; var aFarmTime: int64; var aFarmKey: string): Boolean;
//写日志文件
procedure WriteLog(aQQnum, aLogStr, aAppPah: String);
implementation
//将本地时间转成QQ服务器时间getTime() 方法傳回從1970 年1 月 1 日午夜開始計算的毫秒數function
DateTimeToServerTime(aDateTime: TDateTime): integer;
begin
Result:= DateTimeToUnix(aDateTime)-28800;
end;
//提取字符串
function SubString(aInputStr, aStr_L, aStr_R:string):string; var sPosB,sPosE:integer;
Lwhtml,LwCstr_L,LwCstr_R:string;
begin
Result:='';
if Trim(aInputStr)='' then
Exit;
Lwhtml:= LowerCase(aInputStr);
LwCstr_L := LowerCase(aStr_L);
LwCstr_R := LowerCase(aStr_R);
sPosB:= Pos(LwCstr_L, Lwhtml) + Length(LwCstr_L); sPosE:= PosEx(LwCstr_R, Lwhtml, sPosB);
if (sPosB0) then
Result:=Copy(aInputStr, sPosB, sPosE-sPosB);
end;
function HashStr2BinStr(Hash:string):string;
var
buf:array[0..63] of Char;
i:Integer;
begin
Result:='';
FillChar(buf, SizeOf(buf),0);
SetLength(Result, Round(Length(Hash)/2));
FillChar(Result[1], Length(Result),0);
HexToBin(PChar(Hash), buf,SizeOf(buf));
for i:=0 to Round(Length(Hash)/2)-1 do
Result:= buf;
end;
function Fmd5(str:string):string;
var
md5 : TIdHashMessageDigest5;
longWordRec : T4x4LongWordRecord;
begin
md5 := TIdHashMessageDigest5.Create;
try
{$IFDEF ID10}
Result:= md5.HashStringAsHex(str);
{$ELSE}
longWordRec:= md5.HashV alue(str);
Result:= md5.AsHex(longWordRec);
{$ENDIF}
finally
md5.Free;
end;
end;
function md5_3(str:string):string;
begin
Result:= Fmd5(str);
Result:= HashStr2BinStr(Result);
Result:= Fmd5(Result);
Result:= HashStr2BinStr(Result);
Result:= Fmd5(Result);
end;
function Preprocess(aPassWord, aV erifyCode:string):string; begin
Result:= Fmd5(md5_3(aPassWord) + UpperCase(aV erifyCode));
end;
//取得Flash版本
procedure GetFlaseV ersion(var aStr: string);
var
tmpGerV ersion: string;
tmpIdHTTP: TIdHTTP;
RespData: TStringStream;
begin
try
RespData:= TStringStream.Create('');
tmpIdHTTP:= TIdHTTP.Create(Application);
tmpGerV ersion:= Const_Flase_V ersion+'ini.xml';
tmpIdHTTP.Get(tmpGerV ersion, RespData);
tmpGerV ersion:= Utf8ToAnsi(RespData.DataString);
tmpGerV ersion:= SubString(tmpGerV ersion, 'name="main" url="module/', '"'); if pos('M ain.swf?v=', tmpGerV ersion)=0 then tmpGerV ersion:= 'Main.swf?v=57';
aStr:= Const_Flase_V ersion + tmpGerV ersion;
except
end;
tmpIdHTTP.Free;
end;
//取得验证码
function GetV erifyPic(aIdHTTP:TIdHTTP; var aImage: TImage): boolean;
var
ms:TMemoryStream;
pic:TJPEGImage;
begin
Result:=False;
try
ms:=TMemoryStream.Create;
try
aIdHTTP.Request.SetHeaders;
aIdHTTP.Request.RawHeaders.Clear;
aIdHTTP.Request.Accept:= '*/*';
aIdHTTP.Request.AcceptLanguage:= 'zh-CN';
aIdHTTP.Request.Referer:=
'/doc/0e1483ec4afe04a1b071de5c.html
/cgi-bin/login?link_target=blank&appid=15000102'; aIdHTTP.Request.ContentType:= 'application/x-www-form-urlencoded';
aIdHTTP.Request.AcceptEncoding:= 'gzip, deflate';
/doc/0e1483ec4afe04a1b071de5c.ht ml erAgent:= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'; aIdHTTP.Request.Connection:= 'Keep-Alive';
aIdHTTP.Request.CacheControl:= 'no-cache';
aIdHTTP.Request.Host:=
'/doc/0e1483ec4afe04a1b071de5c.html ';
aIdHTTP.Request.URL:=
Format('/getimage?aid=15000102&%0.15f', [Time()]);
aIdHTTP.Host:= 'p /doc/0e1483ec4afe04a1b071de5c.html ';
aIdHTTP.ReadTimeout:= 15000;
aIdHTTP.Get( Format('/doc/0e1483ec4 afe04a1b071de5c.html /getimage?aid=15000102&%0.15f', [Time()]) , ms);
ms.Position:=0;
pic:=TJPEGImage.Create;
try
pic.LoadFromStream(ms);
aImage.Picture.Assign(pic);
finally
pic.Free;
end;
QQ_Cookie:= '';
QQ_Cookie:= SubString(aIdHTTP.Response.RawHeaders.Text, 'Set-Cookie: verifysession=', ';');
QQ_Cookie:= 'verifysession=' + QQ_Cookie + ';';
V erifySession:= QQ_Cookie;
aIdHTTP.Request.CustomHeaders.Clear;
aIdHTTP.Request.CustomHeaders.Add('Cookie:'+QQ_Cookie );
Result:= True;
finally
ms.Free;
end;
end;
end;
//转换
function Str_Gb2UniCode(text: string): String;
var
i,len: Integer;
cur: Integer;
t: String;
ws: WideString;
begin
Result := '';
ws := text;
len := Length(ws);
i := 1;
while i <= len do
begin
cur := Ord(ws);
FmtStr(t,'%4.4X',[cur]);
Result := Result + t;
Inc(i);
end;
end;
//将汉字转换为unicode码
function AnsiT oUnicode(aSubWideChar: PWideChar):string;
var
tmpLen, iCount: integer;
begin
Result:= '';
tmpLen:= Length(aSubWideChar);
for iCount:= 1 to tmpLen do
Result:= Result + '\u'+IntT oHex(Ord(aSubWideChar[iCount-1]), 2); end;
//将unicode码转换为汉字
function UnicodeT oAnsi(aSubUnicode: string):string;
var
tmpLen, iCount: Integer;
tmpWS: WideString;
tmpWS := '';
iCount := 1;
tmpLen := Length(aSubUnicode);
while iCount <= tmpLen do
try
if (Copy(aSubUnicode, iCount, 1)='\')and
(Copy(aSubUnicode, iCount, 2)='\u') then //'\u7eff\/zq\u75d5'
begin
tmpWS := tmpWS + WideChar(StrT oInt('$' + Copy(aSubUnicode, iCount+2, 4)));
iCount := iCount+6;
end
else
begin
tmpWS := tmpWS + Copy(aSubUnicode, iCount, 1);
iCount := iCount+1;
end;
except
end;
Result := tmpWS;
end;
//以Web形式登录QQ
function LoginQQ(aIdHTTP: TIdHTTP; aUserNameStr, aPasswordStr, aV erifyStr: string; var aWebStr: string): Boolean;
var
PostData, RespData: TStringStream;
tmpS tr: string;
begin
PostData:= TS tringStream.Create( Format(Const_PostLoginInfo, [aUserNameStr, Preprocess(aPasswordStr, aV erifyStr),
aV erifyStr])
+ Const_PostLoginStr);
RespData:= TStringStream.Create('');
Result:= False;
aWebStr:= '';
try
aIdHTTP.ReadTimeout:= 15000;
aIdHTTP.Request.Accept:= 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, */*';
aIdHTTP.Request.ContentType:= 'application/x-www-form-urlencoded';
aIdHTTP.Request.Host:=
'/doc/0e1483ec4afe04a1b071de5c.html ';
aIdHTTP.Request.Referer:=
'/doc/0e1483ec4afe04a1b071de5c.html
/cgi-bin/login?appid=15000102';
/doc/0e1483ec4afe04a1b071de5c.ht ml erAgent:= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
aIdHTTP.Request.AcceptEncoding:= 'gzip, deflate';
aIdHTTP.Request.URL:=
'/doc/0e1483ec4afe04a1b071de5c.html
/login';
//aIdHTTP.Request.SetHeaders;
aIdHTTP.Request.RawHeaders.V alues['Cookie'] := 'Cookie:'+QQ_Cookie;
aIdHTTP.Post('/doc/0e1483ec4afe04a 1b071de5c.html /login', PostData, RespData);
tmpS tr:= Utf8T oAnsi(RespData.DataString);
if pos('如果未能自动跳转,请点击完成跳转。

相关文档
最新文档