source: tools/fio/fio.php

Last change on this file was 2, checked in by chronos, 12 years ago
  • Přidáno: Skript pro import GPC exportu z Fio banky.
File size: 2.4 KB
Line 
1<?php
2
3include('gpc.php');
4
5class Fio
6{
7 var $UserName;
8 var $Password;
9 var $Account;
10
11 function Import($TimeFrom, $TimeTo)
12 {
13 if($this->UserName == '') throw new Exception('Missing value for UserName property.');
14 if($this->Password == '') throw new Exception('Missing value for Password property.');
15 if(!is_numeric($this->Account)) throw new Exception('Missing or not numeric value for Account property.');
16
17 $fp = fsockopen('ssl://www.fio.cz', 443, $errno, $errstr, 30);
18 if(!$fp)
19 {
20 throw new Exception('Connection error: '.$errstr);
21 } else
22 {
23 // Send request
24 $RequestURL = "/scgi-bin/hermes/dz-pohyby.cgi?ID_ucet=".$this->Account.
25 "&LOGIN_USERNAME=".$this->UserName."&SUBMIT=Odeslat&LOGIN_TIME=".time().
26 "&LOGIN_PASSWORD=".$this->Password."&pohyby_DAT_od=".date('d.m.Y', $TimeFrom).
27 "&pohyby_DAT_do=".date('d.m.Y', $TimeTo)."&export_gpc=1";
28 $Request = "GET ".$RequestURL." HTTP/1.1\r\n";
29 $Request .= "Host: www.fio.cz\r\n";
30 $Request .= "User-Agent: PHP Script\r\n";
31 $Request .= "Content-Type: text/html\r\n";
32 $Request .= "Connection: Close\r\n\r\n";
33 fwrite($fp, $Request);
34
35 // Read response
36 $Response = array();
37 while(!feof($fp))
38 {
39 $Response[] = trim(fgets($fp, 1024));
40 }
41 fclose($fp);
42
43 // Strip HTTP header
44 while($Response[0] != '') array_shift($Response);
45 array_shift($Response); // Remove empty line
46 //echo(implode("\n", $Response));
47
48 // Parse all GPC lines
49 $GPC = new GPC();
50 $Result = array();
51 foreach($Response as $Index => $Line)
52 {
53 if(($Index == 0) and (substr($Line, 0, strlen(GPC_TYPE_REPORT)) != GPC_TYPE_REPORT)) $this->NoValidDataError($Response);
54 $GPCLine = $GPC->ParseLine($Line);
55 if($GPCLine != NULL) $Result[] = $GPCLine;
56 }
57 return($Result);
58 }
59 }
60
61 function NoValidDataError($Response)
62 {
63 // Try to get error message
64 // If something go wrong fio show HTML login page and display error message
65 $Response = implode('', $Response);
66 $ErrorMessageStart = '<div id="oldform_warning">';
67 if(strpos($Response, $ErrorMessageStart) !== false)
68 {
69 $Response = substr($Response, strpos($Response, $ErrorMessageStart) + strlen($ErrorMessageStart));
70 $ErrorMessage = trim(substr($Response, 0, strpos($Response, '</div>')));
71 } else $ErrorMessage = '';
72 throw new Exception('No valid GPC data: '.$ErrorMessage);
73 }
74}
75
76?>
Note: See TracBrowser for help on using the repository browser.