|
|
|
Сначала создадим файлы настроек
|
|
|
|
|
|
|
|
**QrCode.Sber.AppPortalSettings.Intf.pas**
|
|
|
|
|
|
|
|
```
|
|
|
|
unit QrCode.Sber.AppPortalSettings.Intf;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
platform.Core.Interfaces,
|
|
|
|
Platform.Core.Sections;
|
|
|
|
|
|
|
|
type
|
|
|
|
/// <summary>
|
|
|
|
/// Модель приложения на портале https://api.developer.sber.ru/
|
|
|
|
/// </summary>
|
|
|
|
IQrCodeSberAppPortalSettings = interface(ISection)
|
|
|
|
['{B029A4EA-EAA3-43FA-B327-9E46B2841039}']
|
|
|
|
function GetClientId: string;
|
|
|
|
function GetClientSecret: string;
|
|
|
|
function GetCertPath: string;
|
|
|
|
function GetCertPassword: string;
|
|
|
|
procedure SetClientId(const AValue: string);
|
|
|
|
procedure SetClientSecret(const AValue: string);
|
|
|
|
procedure SetCertPath(const AValue: string);
|
|
|
|
procedure SetCertPassword(const AValue: string);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Идентификатор клиента
|
|
|
|
/// </summary>
|
|
|
|
property ClientId: string read GetClientId write SetClientId;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Секрет клиента
|
|
|
|
/// </summary>
|
|
|
|
property ClientSecret: string read GetClientSecret write SetClientSecret;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Путь до сертификата
|
|
|
|
/// </summary>
|
|
|
|
property CertPath: string read GetCertPath write SetCertPath;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Пароль к сертификату
|
|
|
|
/// </summary>
|
|
|
|
property CertPassword: string read GetCertPassword write SetCertPassword;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
end.
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
**QrCode.Sber.AppPortalSettings.pas**
|
|
|
|
|
|
|
|
Здесь обратите внимание на 59 строку, где декларируется класс TQrCodeSberAppPortalSettingsSections Именно тут регистрируется тип наших настроек через статический конструктор.
|
|
|
|
|
|
|
|
TRootSections или TSections влияют на то, где будут сохраняться настройки, в корневом файле “ProjectName.ini“ или нет.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Также, следует обратить внимание на то, что свойства должны находиться в protected, а не в public, иначе их не будет видно. Почему так ?
|
|
|
|
|
|
|
|
Ну, а если серьезно, Rtti не видит public секцию, а над SmartObject у нас висит директива {$RTTI EXPLICIT PROPERTIES([vcProtected])}, которая означает “Rtti увидь protected секцию“ )
|
|
|
|
|
|
|
|
```
|
|
|
|
unit QrCode.Sber.AppPortalSettings;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
QrCode.Sber.AppPortalSettings.Intf,
|
|
|
|
Platform.Core.Classes,
|
|
|
|
Platform.Core.Attribute,
|
|
|
|
Platform.Core.Security,
|
|
|
|
Platform.Core.Sections,
|
|
|
|
Platform.Objects.Helper,
|
|
|
|
DataLayer.Interfaces
|
|
|
|
;
|
|
|
|
|
|
|
|
type
|
|
|
|
[Service(TypeInfo(IQrCodeSberAppPortalSettings))]
|
|
|
|
TQrCodeSberAppPortalSettings = class(TSection, IQrCodeSberAppPortalSettings)
|
|
|
|
private
|
|
|
|
FClientId: string;
|
|
|
|
FClientSecret: string;
|
|
|
|
FCertPath: string;
|
|
|
|
FCertPassword: string;
|
|
|
|
|
|
|
|
function GetClientId: string;
|
|
|
|
function GetClientSecret: string;
|
|
|
|
function GetCertPath: string;
|
|
|
|
function GetCertPassword: string;
|
|
|
|
|
|
|
|
procedure SetClientId(const AValue: string);
|
|
|
|
procedure SetClientSecret(const AValue: string);
|
|
|
|
procedure SetCertPath(const AValue: string);
|
|
|
|
procedure SetCertPassword(const AValue: string);
|
|
|
|
protected
|
|
|
|
/// <summary>
|
|
|
|
/// Идентификатор клиента
|
|
|
|
/// </summary>
|
|
|
|
[Serializable]
|
|
|
|
property ClientId: string read GetClientId write SetClientId;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Секрет клиента
|
|
|
|
/// </summary>
|
|
|
|
[Serializable]
|
|
|
|
property ClientSecret: string read GetClientSecret write SetClientSecret;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Путь до сертификата
|
|
|
|
/// </summary>
|
|
|
|
[Serializable]
|
|
|
|
property CertPath: string read GetCertPath write SetCertPath;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Пароль к сертификату
|
|
|
|
/// </summary>
|
|
|
|
[Serializable]
|
|
|
|
property CertPassword: string read GetCertPassword write SetCertPassword;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TQrCodeSberAppPortalSettingsSections = class(TRootSections<TQrCodeSberAppPortalSettingsSections, IQrCodeSberAppPortalSettings>);
|
|
|
|
// TQrCodeSberAppPortalSettingsSections = class(TSections<TQrCodeSberAppPortalSettingsSections, IQrCodeSberAppPortalSettings>);
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{ TQrCodeSberAppPortalSettings }
|
|
|
|
|
|
|
|
function TQrCodeSberAppPortalSettings.GetCertPassword: string;
|
|
|
|
begin
|
|
|
|
Result := FCertPassword;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TQrCodeSberAppPortalSettings.GetCertPath: string;
|
|
|
|
begin
|
|
|
|
Result := FCertPath;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TQrCodeSberAppPortalSettings.GetClientId: string;
|
|
|
|
begin
|
|
|
|
Result := FClientId;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TQrCodeSberAppPortalSettings.GetClientSecret: string;
|
|
|
|
begin
|
|
|
|
Result := FClientSecret;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TQrCodeSberAppPortalSettings.SetCertPassword(const AValue: string);
|
|
|
|
begin
|
|
|
|
FCertPassword := AValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TQrCodeSberAppPortalSettings.SetCertPath(const AValue: string);
|
|
|
|
begin
|
|
|
|
FCertPath := AValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TQrCodeSberAppPortalSettings.SetClientId(const AValue: string);
|
|
|
|
begin
|
|
|
|
FClientId := AValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TQrCodeSberAppPortalSettings.SetClientSecret(const AValue: string);
|
|
|
|
begin
|
|
|
|
FClientSecret := AValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|
|
|
|
```
|
|
|
|
**Интерфейсы инициализаторов
|
|
|
|
|
|
|
|
QrCode.Sber.InitSettings.Intf.pas**
|
|
|
|
```
|
|
|
|
unit QrCode.Sber.InitSettings.Intf;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
platform.Core.Interfaces;
|
|
|
|
|
|
|
|
type
|
|
|
|
ISettingsInitialazer<T: ISection> = interface
|
|
|
|
['{E4C4D2B6-EE74-4053-ABDC-2ECF3F6A74A8}']
|
|
|
|
procedure Execute;
|
|
|
|
end;
|
|
|
|
|
|
|
|
IQrCodeSberSettingsInitializer = interface
|
|
|
|
['{D6A5E980-1028-4574-A533-9A31E345DF69}']
|
|
|
|
procedure Execute;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
end.
|
|
|
|
|
|
|
|
```
|
|
|
|
Собственно инициализация
|
|
|
|
|
|
|
|
QrCode.Sber.InitSettings.pas
|
|
|
|
|
|
|
|
```
|
|
|
|
unit QrCode.Sber.InitSettings;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
platform.Ui.SmartForm,
|
|
|
|
Platform.Core.Attribute,
|
|
|
|
Platform.Objects.Helper,
|
|
|
|
Platform.Core.Classes,
|
|
|
|
Platform.Core.Interfaces,
|
|
|
|
DataLayer.Interfaces,
|
|
|
|
QrCode.Sber.AppPortalSettings.Intf,
|
|
|
|
QrCode.Sber.InitSettings.Intf,
|
|
|
|
Spring.Collections;
|
|
|
|
|
|
|
|
type
|
|
|
|
TInitSettingsProc<T> = reference to procedure(const ASettingsName: string; ASettings: T);
|
|
|
|
|
|
|
|
{TODO: Возможно, вынести этот класс куда-то повыше, возможно кому-то ещё понадобится}
|
|
|
|
|
|
|
|
TSettingsInitialazer<T: ISection> = class(TSmartObject, ISettingsInitialazer<T>)
|
|
|
|
private
|
|
|
|
FSettings: T;
|
|
|
|
FSections: ISections<T>;
|
|
|
|
FSettingsName: string;
|
|
|
|
FInitDataProc: TInitSettingsProc<T>;
|
|
|
|
public
|
|
|
|
constructor Create(ASettingsName: string; AInitDataProc: TInitSettingsProc<T>);
|
|
|
|
procedure Execute;
|
|
|
|
end;
|
|
|
|
|
|
|
|
[Service(TypeInfo(IQrCodeSberSettingsInitializer))]
|
|
|
|
TQrCodeSberSettingsInitializer = class(TSmartObject, IQrCodeSberSettingsInitializer)
|
|
|
|
private
|
|
|
|
procedure InitMainAppSettings;
|
|
|
|
procedure InitTestAppSettings;
|
|
|
|
protected
|
|
|
|
procedure Execute;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{ TSettingsInitialazer<T> }
|
|
|
|
|
|
|
|
constructor TSettingsInitialazer<T>.Create(ASettingsName: string; AInitDataProc: TInitSettingsProc<T>);
|
|
|
|
begin
|
|
|
|
FSettingsName := ASettingsName;
|
|
|
|
FInitDataProc := AInitDataProc;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSettingsInitialazer<T>.Execute;
|
|
|
|
begin
|
|
|
|
FSections := Service<ISections<T>>;
|
|
|
|
FSettings := FSections.Find(FSettingsName);
|
|
|
|
if not Assigned(FSettings) then
|
|
|
|
begin
|
|
|
|
FSettings := Service<T>;
|
|
|
|
FInitDataProc(FSettingsName, FSettings);
|
|
|
|
FSections.Add(FSettings);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TQrCodeSberSettingsInitializer }
|
|
|
|
|
|
|
|
procedure TQrCodeSberSettingsInitializer.Execute;
|
|
|
|
begin
|
|
|
|
InitMainAppSettings;
|
|
|
|
InitTestAppSettings;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TQrCodeSberSettingsInitializer.InitMainAppSettings;
|
|
|
|
var
|
|
|
|
FMainAppInitializer: ISettingsInitialazer<IQrCodeSberAppPortalSettings>;
|
|
|
|
begin
|
|
|
|
FMainAppInitializer := TSettingsInitialazer<IQrCodeSberAppPortalSettings>.Create('MainApp',
|
|
|
|
procedure(const ASettingsName: string; ASettings: IQrCodeSberAppPortalSettings)
|
|
|
|
begin
|
|
|
|
ASettings.Name := ASettingsName;
|
|
|
|
ASettings.ClientId := 'fc24d66b-7fdf-446b-85c4-b013d7372f17';
|
|
|
|
ASettings.ClientSecret := '4aeb384f-ee93-43fb-8278-b62179fa4595';
|
|
|
|
ASettings.CertPassword := 'w2elibs%uPm&rrT,mN||';
|
|
|
|
ASettings.CertPath := '..\sberPortalAppsCerts\certificate_fc24d66b-7fdf-446b-85c4-b013d7372f17.p12';
|
|
|
|
end);
|
|
|
|
|
|
|
|
FMainAppInitializer.Execute;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TQrCodeSberSettingsInitializer.InitTestAppSettings;
|
|
|
|
var
|
|
|
|
FTestAppInitializer: ISettingsInitialazer<IQrCodeSberAppPortalSettings>;
|
|
|
|
begin
|
|
|
|
FTestAppInitializer := TSettingsInitialazer<IQrCodeSberAppPortalSettings>.Create('TestApp',
|
|
|
|
procedure(const ASettingsName: string; ASettings: IQrCodeSberAppPortalSettings)
|
|
|
|
begin
|
|
|
|
ASettings.Name := ASettingsName;
|
|
|
|
ASettings.ClientId := '60ad0d5e-0bac-4677-81ac-dcba16130a23';
|
|
|
|
ASettings.ClientSecret := '1a71690d-3327-47ad-8f45-f0d815e70740';
|
|
|
|
ASettings.CertPassword := '3:HGAr$Z1*K5a&U,Gc/@';
|
|
|
|
ASettings.CertPath := '..\sberPortalAppsCerts\certificate_60ad0d5e-0bac-4677-81ac-dcba16130a23.p12';
|
|
|
|
end);
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|
|
|
|
```
|
|
|
|
После запуска и закрытия программы смотрим в файл рядом с приложением (в моем случае QrCode.Sber.ini) и видим там нечто подобное.
|
|
|
|
```
|
|
|
|
[QrCodeSberAppPortalSettingsSections.Sections.|MainApp|.{B029A4EA-EAA3-43FA-B327-9E46B2841039}.QrCodeSberAppPortalSettings]
|
|
|
|
ClientId=fc24d66b-7fdf-446b-85c4-b013d7372f17
|
|
|
|
ClientSecret=4aeb384f-ee93-43fb-8278-b62179fa4595
|
|
|
|
CertPath=..\sberPortalAppsCerts\certificate_fc24d66b-7fdf-446b-85c4-b013d7372f17.p12
|
|
|
|
CertPassword=w2elibs%uPm&rrT,mN||
|
|
|
|
Presentation=QrCodeSberAppPortalSettings
|
|
|
|
Name=MainApp
|
|
|
|
|
|
|
|
[QrCodeSberAppPortalSettingsSections.Sections.|TestApp|.{B029A4EA-EAA3-43FA-B327-9E46B2841039}.QrCodeSberAppPortalSettings]
|
|
|
|
ClientId=60ad0d5e-0bac-4677-81ac-dcba16130a23
|
|
|
|
ClientSecret=1a71690d-3327-47ad-8f45-f0d815e70740
|
|
|
|
CertPath=..\sberPortalAppsCerts\certificate_60ad0d5e-0bac-4677-81ac-dcba16130a23.p12
|
|
|
|
CertPassword=3:HGAr$Z1*K5a&U,Gc/@
|
|
|
|
Presentation=QrCodeSberAppPortalSettings
|
|
|
|
Name=TestApp
|
|
|
|
```
|
|
|
|
Файл настроек, если понадобится вбивать его руками по аналогии[QrCode.Sber.ini](uploads/edc5a90e3c948b9b4f43ceed85988320/QrCode.Sber.ini) |