· 7 years ago · Sep 20, 2018, 01:28 PM
1<?php
2$codUnic = "39449294";
3$SecretKey = "502EE3C6FA9D31567072B147A33467E7";
4$clientDenumire = "WWW.D-SOFT-RO SRL";
5$hash = strtoupper(SHA1($codUnic . $SecretKey . $clientDenumire));
6$tip = 'PJ';
7$nrRegCom = 'J22/1485/06.06.2018';
8$judet = 'Iasi';
9$text = 'test';
10$explicatii = 'something here';
11$valuta = 'RON';
12$tipFactura = 'Factura';
13$continutDenumire = 'Produs';
14$continutPretUnitar = 10.60;
15$continutUnitate = 'buc';
16$continutNrProduse = '2';
17$continutTva = 19.00;
18$dataEmitere = "2018/09/20";
19$numar = "00002";
20$serie = "IS";
21$email = "officedsoft@gmail.com";
22$telefon = "0865375645";
23$tara = "Romania";
24$adresa = "sdfdfdfd";
25$codArticol = "12345";
26$descriere = "3435343434jgfjddh";
27$pretTotal = 1234.98;
28$TvaLaIncasare = "true";
29$idExtern = 2;
30
31$data = array(
32 'CodUnic' => $codUnic,
33 'Hash' => $hash,
34 'Text' => $text,
35 'Explicatii' => $explicatii,
36 'Valuta' => $valuta,
37 'TipFactura' => $tipFactura,
38 'DataEmitere' => $dataEmitere,
39 "Numar" => $numar,
40 "Serie" => $serie,
41 "TvaLaIncasare" => $TvaLaIncasare,
42 "Client" => array(
43 "Denumire" => $clientDenumire,
44 "CodUnic" => $codUnic,
45 "NrRegCom" => $nrRegCom,
46 "Email" => $email,
47 "Telefon" => $telefon,
48 "Tara" => $tara,
49 "Judet" => $judet,
50 "Adresa" => $adresa,
51 "Tip" => $tip,
52 "IdExtern" => $idExtern
53 ),
54 "Continut[0]" => array(
55 "Denumire" => $continutDenumire,
56 "CodArticol" => $codArticol,
57 "Descriere" => $descriere,
58 "PretUnitar" => $continutPretUnitar,
59 "PretTotal" => $pretTotal,
60 "UM" => $continutUnitate,
61 "NrProduse" => $continutNrProduse,
62 "CotaTVA" => $continutTva,
63 )
64);
65
66$data_string = json_encode($data);
67
68$ch = curl_init('http://testapp.fgo.ro/publicws/factura/emitere');
69curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
70curl_setopt($ch, CURLOPT_HTTPHEADER, [$SecretKey]);
71curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
72curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
73curl_setopt($ch, CURLOPT_HTTPHEADER, array(
74 'Content-Type: application/json',
75 'Content-Length: ' . strlen($data_string),
76 'Authorization: Basic ' . $SecretKey
77 )
78);
79
80$result = curl_exec($ch);
81if ($result === true) {
82 echo "Success!";
83}
84echo $result;
85?>
86<script type="text/javascript">
87 console.log(<?=json_encode($data)?>);
88</script>