{*******************************************************} { } { ThdRcvPolicy } { } { Copyright (C) 2025 kku } { } {*******************************************************} unit ThdRcvPolicy; interface uses Tocsg.Thread, System.SysUtils, Winapi.Windows, Winapi.Messages, Tocsg.Win32, IdHTTP, IdSSLOpenSSL; const WM_NOTI_RCVPOLICY = WM_USER + 1547; MTX_NAME_RCVPOLICY = 'RcvPol250324'; type TThdRcvPolicy = class(TTgThread) protected hRcvWnd_: HWND; Mtx_: TTgMutex; HTTP_: TIdHTTP; SSL_: TIdSSLIOHandlerSocketOpenSSL; procedure Execute; override; public Constructor Create(aRcvWnd: HWND); Destructor Destroy; override; end; implementation uses ProcessServerAPI, Tocsg.Exception, Condition, ProcessPrint; { TThdRcvPolicy } Constructor TThdRcvPolicy.Create(aRcvWnd: HWND); procedure InitHttp; begin try SSL_ := TIdSSLIOHandlerSocketOpenSSL.Create(nil); SSL_.SSLOptions.Method := sslvSSLv23; SSL_.SSLOptions.SSLVersions := [sslvTLSv1_2, sslvTLSv1_1, sslvTLSv1]; HTTP_ := TIdHTTP.Create(nil); HTTP_.IOHandler := SSL_; with HTTP_ do begin // HandleRedirects := true; // Request.BasicAuthentication := true; Request.Clear; Request.UserAgent := 'Mozilla/5.0'; Request.ContentType := 'application/json; charset=utf-8'; //'application/xml'; Request.Accept := 'application/json; charset=utf-8'; Request.Charset := 'utf-8'; // Request.Connection := 'Keep-Alive'; // Request.CustomHeaders.Values['Keep-Alive'] := 'timeout=300, max=100'; Request.Connection := 'close'; HTTPOptions := HTTPOptions - [hoKeepOrigProtocol]; case CUSTOMER_TYPE of CUSTOMER_DEMO : begin ConnectTimeout := 3000; ReadTimeout := 10000; end; CUSTOMER_KFTC : begin ConnectTimeout := 3000; ReadTimeout := 30000; end; CUSTOMER_KR : begin ConnectTimeout := 10000; ReadTimeout := 60000; end; CUSTOMER_SHCD : begin // 신한카드 타임아웃 180초 23_0327 14:18:03 kku // 다시 30, 60초로 변경 23_0410 08:28:17 kku ConnectTimeout := 30000; ReadTimeout := 60000; end; else begin ConnectTimeout := 5000; ReadTimeout := 30000; end; end; end; except end; end; begin Inherited Create; hRcvWnd_ := aRcvWnd; Mtx_ := TTgMutex.Create(MTX_NAME_RCVPOLICY); InitHttp; FreeOnTerminate := true; StartThread; end; Destructor TThdRcvPolicy.Destroy; begin FreeAndNil(Mtx_); Inherited; end; procedure TThdRcvPolicy.Execute; begin try if hRcvWnd_ <> 0 then begin if ProcessRcvPolicy(rpkAll, '', '', HTTP_) then PostMessage(hRcvWnd_, WM_NOTI_RCVPOLICY, 1, 0) else PostMessage(hRcvWnd_, WM_NOTI_RCVPOLICY, 0, 0); end; if CUSTOMER_TYPE = CUSTOMER_KIMCHANG then ProcessRcv_xPrintData(HTTP_, [xpdEmp, xpdPrts, xpdBill, xpdMkcd, xpdLump], true); except on E: Exception do begin ETgException.TraceException(Self, E, 'Fail .. Execute()'); PostMessage(hRcvWnd_, WM_NOTI_RCVPOLICY, 2, 0); end; end; end; end.