SHARE
TWEET

Untitled

a guest Nov 27th, 2017 148 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  7.   Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IPPeerClient, Vcl.StdCtrls,
  8.   REST.Client, Data.Bind.Components, Data.Bind.ObjectScope, System.JSON, FireDAC.Stan.Intf,
  9.   FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf,
  10.   FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.FB,
  11.   FireDAC.Phys.FBDef, FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS,
  12.   FireDAC.DApt.Intf, FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client;
  13.  
  14. type
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Memo1: TMemo;
  18.     FDConnection1: TFDConnection;
  19.     FDQuery1: TFDQuery;
  20.     procedure Button1Click(Sender: TObject);
  21.   private
  22.     { Private declarations }
  23.   public
  24.     { Public declarations }
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.   result: string;
  30.   dynRESTcl: TRESTClient;
  31.   dynRESTresp: TRESTResponse;
  32.   dynRESTreq: TRESTRequest;
  33.  
  34. implementation
  35.  
  36. {$R *.dfm}
  37.  
  38. procedure TForm1.Button1Click(Sender: TObject);
  39. var
  40.   Json: TJSONObject;
  41.   distance: string;
  42. begin
  43.   dynRESTcl := TRESTClient.Create('https://hst-api.wialon.com');
  44.   dynRESTreq := TRESTRequest.Create(nil);
  45.   dynRESTresp := TRESTResponse.Create(nil);
  46.   dynRESTreq.Client := dynRESTcl;
  47.   dynRESTreq.Response := dynRESTresp;
  48.   dynRESTreq.Resource := '/wialon/ajax.html';
  49.  
  50.   dynRESTreq.Params.AddItem('svc', 'token/login');
  51.   dynRESTreq.Params.AddItem('params', '{"token":"70f9f415e166fac32b278ce32c7bfde38A1EF034592F606C4103D059699590E0A5EBBC9D"}');
  52.   dynRESTreq.Execute;
  53.  
  54.   Json := TJSONObject.ParseJSONValue(dynRESTresp.Content) as TJSONObject;
  55.   if not Assigned(Json) then
  56.     raise Exception.Create('Файл не содержит JSON-данные');
  57.   result := Json.Get('eid').JsonValue.Value;
  58.  
  59.   FDQuery1.Active := True;
  60.   FDQuery1.First;
  61.  
  62.   while not FDQuery1.eof do
  63.   begin
  64.     dynRESTreq.Params.AddItem('svc', 'core/search_item');
  65.     dynRESTreq.Params.AddItem('params', '{"id":' + FDQuery1.FieldByName('car_wialon_id').AsString + ',"flags":4294967295}');
  66.     dynRESTreq.Params.AddItem('sid', result);
  67.  
  68.     dynRESTreq.Execute;
  69.  
  70.     Json := TJSONObject.ParseJSONValue(dynRESTresp.Content) as TJSONObject;
  71.     distance := (Json.Get('item').JsonValue as TJSONObject).Get('cnm').JsonValue.Value;
  72.  
  73.     ShowMessage(FDQuery1.FieldByName('car_reg_number').AsString + ': ' + distance);
  74.  
  75.     FDQuery1.Next;
  76.   end;
  77.  
  78. end;
  79.  
  80. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top