1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
| unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls
, System.Net.HttpClient;
type
TForm2 = class(TForm)
Authentification: TButton;
Envoyer: TButton;
Memo_Token: TMemo;
procedure AuthentificationClick(Sender: TObject);
procedure EnvoyerClick(Sender: TObject);
private
F_Token,
F_Http_Query,
F_Http_Body,
F_Content_Type,
F_Content_Encoding,
f_motdepasse: String;
F_Query_Get_Stream: TStringStream;
F_HttpClient: THttpClient;
F_HttpResponse: IHttpResponse;
function Do_Execute_Query_Post: String;
procedure Prepare_Query_Get_Stream(aParametre: String);
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form2: TForm2;
implementation
uses System.ZLib;
{$R *.dfm}
procedure TForm2.AuthentificationClick(Sender: TObject);
begin
f_motdepasse := '6AQ3UKQH';
F_Http_Query := 'https://mon.urssaf.fr/authentifier_dpae';
F_Content_Type := 'application/xml';
F_Http_Body := '<identifiants>'
+ '<siret>0000000000</siret>'
+ '<nom>nom</nom>'
+ '<prenom>prenom</prenom>'
+ '<motdepasse>motdepasse</motdepasse>'
+ '<service>25</service>'
+ '</identifiants>';
Do_Execute_Query_Post;
F_Token := F_HttpResponse.ContentAsString();
Memo_Token.Text :=
'StatusCode=' + inttostr(F_HttpResponse.StatusCode) + #13
+ 'StatusText=' + F_HttpResponse.StatusText + #13
+ 'Content=' + F_HttpResponse.ContentAsString() + #13
end;
procedure TForm2.Prepare_Query_Get_Stream(aParametre: String);
var
s: string;
function ZCompressString(aText: string): string;
var
strInput: TStringStream;
begin
F_Query_Get_Stream := TStringStream.Create;
strInput := TStringStream.Create(aText);
strInput.Seek(0, TSeekOrigin.soBeginning);
ZCompressStream(strInput, F_Query_Get_Stream);
end;
begin
FreeAndnil(F_Query_Get_Stream);
F_Query_Get_Stream := nil;
if aParametre <> '' then
begin
if F_Content_Encoding = '' then
begin
F_Query_Get_Stream := TStringStream.Create(aParametre, TEncoding.UTF8);
end
else
begin
ZCompressString(aParametre);
end;
end;
end;
function TForm2.Do_Execute_Query_Post: String;
var
F_HttpClient: THttpClient;
begin
try
F_HttpClient := THttpClient.Create;
F_HttpClient.ContentType := F_Content_Type;
if F_Content_Encoding <> '' then
begin
F_HttpClient.AcceptEncoding := F_Content_Encoding;
F_HttpClient.CustomHeaders['Content-Encoding'] := F_Content_Encoding;
end;
if F_Token <> '' then
F_HttpClient.CustomHeaders['Authorization'] := 'DSNLogin jeton=' + F_Token + #13;
Prepare_Query_Get_Stream(F_Http_Body);
F_HttpResponse := F_HttpClient.Post(F_Http_Query, F_Query_Get_Stream);
result := F_HttpResponse.ContentAsString();
FreeAndnil(F_Query_Get_Stream);
finally
F_HttpClient.DisposeOf;
end;
end;
procedure TForm2.EnvoyerClick(Sender: TObject);
function GET_DUE: String;
begin
result :=
' <?xml version="1.0" encoding="UTF-8"?> '
+ ' <FR_DUE_Upload xmlns:cct="urn:oasis:names:tc:ubl:corecomponentTypes:1.0:0.70" '
+ ' xmlns:rxdt="http://www.repxml.org/DataTypes" xmlns:rxorg="http://www.repxml.org/Organization" xmlns:rxpadr="http://www.repxml.org/PostalAddress" xmlns:rxpers="http://www.repxml.org/Person_Identity" '
+ ' xmlns:rxphadr="http://www.repxml.org/PhoneAddress" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> '
+ ' <FR_DUE_Upload.Test.Indicator>120</FR_DUE_Upload.Test.Indicator> '
+ ' <FR_DuesGroup> '
+ ' <FR_Employer> '
+ ' <FR_EmployerIdentity> '
+ ' <rxorg:FR_Organization.SIRET.Identifier>99999999999999</rxorg:FR_Organization.SIRET.Identifier> '
+ ' <rxorg:FR_Organization.APE.Code>8110Z</rxorg:FR_Organization.APE.Code> '
+ ' </FR_EmployerIdentity> '
+ ' <FR_Employer.URSSAF.Code>257</FR_Employer.URSSAF.Code> '
+ ' <FR_EmployerAddress> '
+ ' <rxpadr:FR_PostalAddress.StreetDesignation.Text>44 rue DES TEST</rxpadr:FR_PostalAddress.StreetDesignation.Text> '
+ ' <rxpadr:FR_PostalAddress.Town.Text>CAEN</rxpadr:FR_PostalAddress.Town.Text> '
+ ' <rxpadr:FR_PostalAddress.Postal.Code>14000</rxpadr:FR_PostalAddress.Postal.Code> '
+ ' </FR_EmployerAddress> '
+ ' <FR_EmployerContact> '
+ ' <FR_PhoneNumber> '
+ ' <rxphadr:FR_PhoneAddress.PhoneNumber.Text>0000000000</rxphadr:FR_PhoneAddress.PhoneNumber.Text> '
+ ' </FR_PhoneNumber> '
+ ' </FR_EmployerContact> '
+ ' </FR_Employer> '
+ ' <FR_EmployeeGroup> '
+ ' <FR_Employee> '
+ ' <FR_EmployeeIdentity> '
+ ' <rxpers:FR_PersonIdentity.Surname.Text>TEST</rxpers:FR_PersonIdentity.Surname.Text> '
+ ' <rxpers:FR_PersonIdentity.ChristianName.Text>Alain</rxpers:FR_PersonIdentity.ChristianName.Text> '
+ ' <rxpers:FR_PersonIdentity.Sex.Code>1</rxpers:FR_PersonIdentity.Sex.Code> '
+ ' <rxpers:FR_NNI> '
+ ' <rxpers:FR_NNI.NIR.Identifier>1000000000000</rxpers:FR_NNI.NIR.Identifier> '
+ ' <rxpers:FR_NNI.NIRKey.Text>11</rxpers:FR_NNI.NIRKey.Text> '
+ ' </rxpers:FR_NNI> '
+ ' <rxpers:FR_Birth> '
+ ' <rxpers:FR_Birth.Date>1970-01-01</rxpers:FR_Birth.Date> '
+ ' <rxpers:FR_Birth.Town.Text>PARIS</rxpers:FR_Birth.Town.Text> '
+ ' </rxpers:FR_Birth> '
+ ' </FR_EmployeeIdentity> '
+ ' <FR_EmployeeComplement> '
+ ' <FR_EmployeeComplement.Birth_Department.Code>75</FR_EmployeeComplement.Birth_Department.Code> '
+ ' </FR_EmployeeComplement> '
+ ' </FR_Employee> '
+ ' <FR_Contract> '
+ ' <FR_Contract.StartContract.Date>2020-08-17</FR_Contract.StartContract.Date> '
+ ' <FR_Contract.StartContract.Time>12:30:00</FR_Contract.StartContract.Time> '
+ ' <FR_Contract.EndContract.Date>2020-09-15</FR_Contract.EndContract.Date> '
+ ' <FR_Contract.Nature.Code>CDI</FR_Contract.Nature.Code> '
+ ' <FR_Contract.HealthService.Text>387</FR_Contract.HealthService.Text> '
+ ' </FR_Contract> '
+ ' </FR_EmployeeGroup> '
+ ' </FR_DuesGroup> '
+ ' </FR_DUE_Upload> ';
end;
begin
F_Http_Body := GET_DUE;
F_Content_Type := 'text/plain'; // 'application/xml';
F_Content_Encoding := 'gzip';
F_Http_Query := 'https://depot.dpae-edi.urssaf.fr/deposer-dsn/1.0';
Do_Execute_Query_Post;
Memo_Token.Text :=
'StatusCode=' + inttostr(F_HttpResponse.StatusCode) + #13#10
+ 'StatusText=' + F_HttpResponse.StatusText + #13#10
+ 'Content=' + F_HttpResponse.ContentAsString() + #13#10
end;
end. |
Partager