unit Unit4; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, AppCentreCom_TLB, StdCtrls, ExtCtrls; type TForm4 = class(TForm) pnl1: TPanel; edt1: TEdit; edt2: TEdit; lbl1: TLabel; lbl2: TLabel; lbl3: TLabel; btn1: TButton; pnl2: TPanel; pnl3: TPanel; procedure FormCreate(Sender: TObject); procedure btn1Click(Sender: TObject); private function Login(AUserName, APassword: string): Boolean; function AuthLogin(ALoginName: string): Boolean; public { Public declarations } end; TAuthLogin = class(TThread) private FURL, FAppSecrit: string; FForm: TForm4; public procedure Execute; override; end; var Form4: TForm4; implementation uses Registry, AppCentreINI, superobject; {$R *.dfm} //procedure TForm4.btn1Click(Sender: TObject); //var // AppCentreCom: ILXTAppCentreCom; // ptr: PChar; //begin // AppCentreCom := CoLXTAppCentreCom.Create; // ptr := AppCentreCom.GetInstallationDirectory(PChar('aa')); // if ptr <> nil then // ShowMessage(string(ptr)); //end; //procedure TForm4.btn2Click(Sender: TObject); //const // APPCENTRE_REGISTRY: string = 'SOFTWARE\Winsoft\AppCentre\Directory'; //var // ARegistry: TRegistry; //begin // ARegistry := TRegistry.Create; // try // ARegistry.RootKey := HKEY_LOCAL_MACHINE; // if ARegistry.OpenKey(APPCENTRE_REGISTRY, True) then // begin // if ARegistry.ValueExists('aa') then // // ShowMessage(ARegistry.ReadString('test')); // end; // finally // ARegistry.CloseKey; // ARegistry.Free; // end; //end; function TForm4.AuthLogin(ALoginName: string): Boolean; begin if SameText(ALoginName, 'csttf') then begin pnl2.Caption := ALoginName + ',您已成功登陆!'; pnl2.BringToFront; end else begin ShowMessage(ALoginName + '账号不存在,可能账号绑定错误,请联系管理员!'); end; end; procedure TForm4.btn1Click(Sender: TObject); begin if Login(edt1.Text, edt2.Text) then begin pnl2.Caption := edt1.Text + ',您已成功登陆!'; pnl2.BringToFront; end else begin ShowMessage('用户名和密码不对!'); end; end; procedure TForm4.FormCreate(Sender: TObject); var AppCentreCom: ILXTAppCentreCom; AThread: TAuthLogin; ALoginName: string; jo: ISuperObject; begin IniOptions.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'appcentre.ini'); AppCentreCom := CoLXTAppCentreCom.Create; if ParamCount >= 1 then begin ALoginName := string(AppCentreCom.Authenticate(PChar(ParamStr(1)), PChar(IniOptions.AppCentreAppSecret))); if ALoginName <> ''then begin ShowMessage(ALoginName); jo := SO(ALoginName); ALoginName := jo.S['id']; AuthLogin(ALoginName); end; end else begin AppCentreCom.RegisterInstallationDirectory(PChar(IniOptions.AppCentreAppKey), PChar(ParamStr(0))); end; end; function TForm4.Login(AUserName, APassword: string): Boolean; begin Result := SameText(edt1.Text, 'csttf') and SameText(edt2.Text, '12345678'); end; { TAuthLogin } procedure TAuthLogin.Execute; var AppCentreCom: ILXTAppCentreCom; AppToken: string; ALoginName: string; jo: ISuperObject; begin AppCentreCom := CoLXTAppCentreCom.Create; ALoginName := string(AppCentreCom.Authenticate(PChar(FURL), PChar(FAppSecrit))); if ALoginName <> ''then begin jo := SO(ALoginName); ALoginName := jo.S['id']; FForm.AuthLogin(ALoginName); end; end; end.