unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,ComObj;

type
  TMainForm = class(TForm)
    Label2: TLabel;
    Edit_DatiKey: TEdit;
    Button_GetKey: TButton;
    Edit_UserName: TEdit;
    Edit_UserPass: TEdit;
    Label3: TLabel;
    Button1: TButton;
    Label4: TLabel;
    Button_Report: TButton;
    Label5: TLabel;
    Label6: TLabel;
    Button_Check: TButton;
    Label7: TLabel;
    Button_SetSoftKey: TButton;
    Edit_SoftKey: TEdit;
    Label8: TLabel;
    Button_SetFather: TButton;
    Edit_FatherID: TEdit;
    Label9: TLabel;
    Button_Reg: TButton;
    Edit_RegName: TEdit;
    Edit_RegPass: TEdit;
    Edit_RegFather: TEdit;
    procedure Button_GetKeyClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button_ReportClick(Sender: TObject);
    procedure Button_CheckClick(Sender: TObject);
    procedure Button_SetSoftKeyClick(Sender: TObject);
    procedure Button_SetFatherClick(Sender: TObject);
    procedure Button_RegClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
{
var SendFile(string UserKey, int GameId, string ImgPath, int OverTime)
var SendImage(string UserKey, int GameId, int StartX, int StartY, int Width, int Height, int OverTime)
var GetAnswer(string Tid)
var Report(string Tid, string UserKey)
var LogIn(string UserName, string UserPwd)
var RegUser(string UserName, string UserPwd, string extUserName)
var Pay(string cardNum, string cardPwd, string UserName)
var Check(string UserKey)
var SetSoftKey(string SoftKey)
var Enable(string UseLog)
var SetFather(string FId)
var SendStream(string UserKey, int GameId, int StreamP, int StreamSize, int OverTime)
var LogInEx(string UserName, string UserPwd, string FatherKey)
var SetQuality(int Quality)
var SetLogName(string LogName)
}
    type
    TLogIn= Function (UserName,UserPwd:PAnsiChar):PAnsiChar;stdcall;
    type
    TSendFile= Function (UserKey:PAnsiChar;GameID:integer;path:PAnsiChar;BadTime: Integer):PAnsiChar;stdcall;
    type
    TGetAnswer= Function (TID:PAnsiChar):PAnsiChar;stdcall;
    type
    TReport= Function (TID, UserKey: PAnsiChar):PAnsiChar;stdcall;
    type
    TCheck= Function (UserKey:PAnsiChar):PAnsiChar;stdcall;
    type
     
    TSetSoftKey= Function (SoftKey: PAnsiChar):PAnsiChar;stdcall;
    type
    TSetFather= Function (FId: PAnsiChar):PAnsiChar;stdcall;
    type
    TRegUser= Function (UserName,UserPwd,extUserName: PAnsiChar):PAnsiChar;stdcall;
  
var
  MainForm: TMainForm;
  LogIn:TLogIn;
  SendFile:TSendFile;
  GetAnswer:TGetAnswer;
  Report:TReport;
  Check:TCheck;
  SetSoftKey:TSetSoftKey;
  SetFather:TSetFather;
  RegUser:TRegUser;
  
  Key:AnsiString; //答题密码串
  TID:AnsiString;//服务器返回的题目id
implementation

{$R *.dfm}


procedure TMainForm.FormCreate(Sender: TObject);
var
 DLLHandle:dword;

begin
  DLLHandle := LoadLibrary(pchar(ExtractFilePath(Application.Exename)+'QQQDaTi.dll'));
  LogIn:=GetProcAddress(DLLHandle, 'LogIn');
  SendFile:=GetProcAddress(DLLHandle, 'SendFile');
  GetAnswer:=GetProcAddress(DLLHandle, 'GetAnswer');
  Report:=GetProcAddress(DLLHandle, 'Report');
  Check:=GetProcAddress(DLLHandle, 'Check');
  SetSoftKey:=GetProcAddress(DLLHandle, 'SetSoftKey');
  SetFather:=GetProcAddress(DLLHandle, 'SetFather');
  RegUser:=GetProcAddress(DLLHandle, 'RegUser');

  if not Assigned(@LogIn) then
  begin
    showmessage('调用LogIn失败');
    Close;
  end ;
  if not Assigned(@SendFile) then
  begin
    showmessage('调用SendFile失败');
    Close;
  end ;
  if not Assigned(@GetAnswer) then
  begin
    showmessage('调用GetAnswer失败');
    Close;
  end ;
  if not Assigned(@Report) then
  begin
    showmessage('调用Report失败');
    Close;
  end;
  if not Assigned(@Check) then
  begin
    showmessage('调用Check失败');
    Close;
  end;
  if not Assigned(@SetSoftKey) then
  begin
    showmessage('调用SetSoftKey失败');
    Close;
  end;
  if not Assigned(@SetFather) then
  begin
    showmessage('调用SetFather失败');
    Close;
  end;
  if not Assigned(@RegUser) then
  begin
    showmessage('调用RegUser失败');
    Close;
  end;

end;


procedure TMainForm.Button1Click(Sender: TObject);
var
R:AnsiString;
GameID:Integer;
ImgPath:AnsiString;
OverTime:Integer;
T:integer;
Answer:AnsiString;
begin
  GameID:=2000;  //游戏类型id ,具体登录www.3QDaTi.com,查阅游戏类型id
  ImgPath:=ExtractFilePath(Application.Exename)+'Test.jpg'; //答题图片路径
  OverTime:=30; //超时时间
  

  T:=0;
  while (T<5)and(Length(R)<10) do
  begin
     //var SendFile(string UserKey, int GameId, string ImgPath, int OverTime)
    R:=SendFile(PAnsiChar(Key),GameID,PAnsiChar(ImgPath),OverTime);
    T:=T+1;
    Sleep(100);
  end;

  if Length(R)>10 then
  begin
    TID:=R;
    T:=0;
    //var GetAnswer(string Tid)
    R:=GetAnswer(PAnsiChar(TID));

    while (R='-99')and(T<(OverTime)) do
    begin
      R:=GetAnswer(PAnsiChar(TID));
      Sleep(1000);
    end;

    if StrToIntDef(R,0)>=0 then
    begin
      Answer:=R;
      ShowMessage('答题完成,返回答案='+Answer);
    end else
    begin
      ShowMessage('获取GetAnswer失败,返回错误代码='+R+',具体错误请参考插件说明中的返回值说明');
      exit;
    end;
    
    
  end else
  begin
    ShowMessage('获取SendFile失败,返回错误代码='+R+',具体错误请参考插件说明中的返回值说明');
  end;
end;

procedure TMainForm.Button_CheckClick(Sender: TObject);
var
 R:AnsiString;
begin

  //var Check(string UserKey)
  R:=Check(PAnsiChar(Key));
  if StrToIntDef(R,0)>=0 then
  begin

    ShowMessage('剩余题分='+R);
  end else
  begin
    ShowMessage('获取Check失败,返回错误代码='+R+',具体错误请参考插件说明中的返回值说明');
    exit;
  end;
  
end;

procedure TMainForm.Button_GetKeyClick(Sender: TObject);
var
  UserName:AnsiString;
  UserPass:AnsiString;
  R:AnsiString;
begin



   UserName:=Edit_UserName.Text;
   UserPass:=Edit_UserPass.Text;
   


   R:=LogIn(PAnsiChar(UserName),PAnsiChar(UserPass));

   if Length(R)>10 then
   begin
     Key:=R;
     Edit_DatiKey.Text:=Key;
     ShowMessage('获取key成功');
   end else
   begin
     ShowMessage('获取key失败,返回错误代码='+R+',具体错误请参考插件说明中的返回值说明');
   end;
end;

procedure TMainForm.Button_RegClick(Sender: TObject);
var
  R:AnsiString;
  RegUserName,RegUserPass,extUserName:AnsiString;
begin
  RegUserName:=Edit_RegName.Text;
  RegUserPass:=Edit_RegPass.Text;
  extUserName:=Edit_RegFather.Text;
  //var RegUser(string UserName, string UserPwd, string extUserName)
  R:=RegUser(PAnsiChar(RegUserName),PAnsiChar(RegUserPass),PAnsiChar(extUserName));
  if StrToIntDef(R,-1)>=0 then
  begin

    ShowMessage('注册成功');
  end else
  begin
    ShowMessage('获取RegUser失败,返回错误代码='+R+',具体错误请参考插件说明中的返回值说明');
    exit;
  end;
  
end;

procedure TMainForm.Button_ReportClick(Sender: TObject);
var
  R:AnsiString;
begin

    //var Report(string Tid, string UserKey)
  R:=Report(PAnsiChar(TID),PAnsiChar(Key));
  if R='0' then
  begin
    ShowMessage('申诉成功,等待管理员审核.');
  end else
  begin
   ShowMessage('获取Report失败,返回错误代码='+R+',具体错误请参考插件说明中的返回值说明');
  end;
end;



procedure TMainForm.Button_SetFatherClick(Sender: TObject);
var
 R:AnsiString;
 FathID:AnsiString;
begin
   //设置了父系,通过此软件答题的密码串必须是父系本身或者是其子账户的密码串,其余密码串无法答题.
   //父系ID就是父系的密码串前面的数字(例如密码是601|EA700D07-514E-4C3E-8888-C45600B6CBF1,那么父系ID就是601)
  FathID:=Edit_FatherID.Text;  
       
    //var SetFather(string FId)
  R:=SetFather(PAnsiChar(FathID));
  if StrToIntDef(R,-1)>=0 then
  begin

    ShowMessage('设置成功');
  end else
  begin
    ShowMessage('获取Edit_FatherID失败,返回错误代码='+R+',具体错误请参考插件说明中的返回值说明');
    exit;
  end;

end;

procedure TMainForm.Button_SetSoftKeyClick(Sender: TObject);
var
 R:AnsiString;
 vSoftKey:AnsiString;
begin
   //设置作者返利key 只需要在注册插件成功后设置一次即可,无须重复设置.
   //请到官网登录作者账号获取作者KEY(作者KEY例如=A6E63EC2-13D4-4958-944C-1A1657171A43)
  vSoftKey:=Edit_SoftKey.Text;
  //var SetSoftKey(string SoftKey)
  R:=SetSoftKey(PAnsiChar('123'));
  if StrToIntDef(R,-1)>=0 then
  begin

    ShowMessage('设置成功');
  end else
  begin
    ShowMessage('获取SetSoftKey失败,返回错误代码='+R+',具体错误请参考插件说明中的返回值说明');
    exit;
  end;
end;

end.
