GPC export z Fio banky: Porovnání verzí
Skočit na navigaci
Skočit na vyhledávání
Smazaný obsah Přidaný obsah
Založena nová stránka: ==Vnější odkazy== * [http://sworktech.com/blog/index.php?/archives/190-Parsovani-GPC-souboru-v-PHP.html Parsování GPC souborů v PHP] Kategorie:Programování |
Bez shrnutí editace |
||
| Řádek 1: | Řádek 1: | ||
==Ukázkové soubory== |
|||
===Třída GPC v gpc.php=== |
|||
<pre><?php |
|||
define('GPC_TYPE_REPORT', '074'); |
|||
define('GPC_TYPE_ITEM', '075'); |
|||
class GPC |
|||
{ |
|||
function substr($inputstring, $start, $count) |
|||
{ |
|||
return(substr($inputstring, $start - 1, $count)); |
|||
} |
|||
function ParseLine($Line) |
|||
{ |
|||
$Line = ' '.$Line; |
|||
$Type = substr($Line, 1, 3); |
|||
if($Type == GPC_TYPE_REPORT) |
|||
{ |
|||
$GPCLine = array |
|||
( |
|||
'Type' => GPC_TYPE_REPORT, |
|||
'AccountNumber' => substr($Line, 4, 16), |
|||
'AccountName' => trim(substr($Line, 20, 20)), |
|||
'OldBalanceDate' => mktime(0, 0, 0, substr($Line, 42, 2), substr($Line, 40, 2), '20'.substr($Line, 44, 2)), |
|||
'OldBalanceValue' => (substr($Line, 60, 1).substr($Line, 46, 14)) / 100, |
|||
'NewBalanceValue' => (substr($Line, 75, 1).substr($Line, 61, 14)) / 100, |
|||
'DebitValue' => (substr($Line, 90, 1).substr($Line, 76, 14)) / 100, |
|||
'CreditValue' => (substr($Line, 105, 1).substr($Line, 91, 14)) / 100, |
|||
'SequenceNumber' => intval(substr($Line, 106, 3)), |
|||
'Date' => mktime(0, 0, 0, substr($Line, 111, 2), substr($Line, 109, 2), '20'.substr($Line, 113, 2)), |
|||
//'DataAlignment' => substr($Line, 115, 14), |
|||
'CheckSum' => sha1(md5($Line).$Line), |
|||
); |
|||
} else |
|||
if($Type == GPC_TYPE_ITEM) |
|||
{ |
|||
$GPCLine = array |
|||
( |
|||
'Type' => GPC_TYPE_ITEM, |
|||
'AccountNumber' => substr($Line, 4, 16), |
|||
'OffsetAccount' => substr($Line, 20, 16), |
|||
'RecordNumber' => substr($Line, 36, 13), |
|||
'Value' => substr($Line, 49, 12) / 100, |
|||
'Code' => substr($Line, 61, 1), |
|||
'VariableSymbol' => intval(substr($Line, 62, 10)), |
|||
'BankCode' => substr($Line, 74, 4), |
|||
'ConstantSymbol' => intval(substr($Line, 78, 4)), |
|||
'SpecificSymbol' => intval(substr($Line, 82, 10)), |
|||
'Valut' => substr($Line, 92, 6), |
|||
'ClientName' => substr($Line, 98, 20), |
|||
//'Zero' => substr($Line, 118, 1), |
|||
'CurrencyCode' => substr($Line, 119, 4), |
|||
'DueDate' => mktime(0, 0, 0, substr($Line, 125, 2), substr($Line, 123, 2), substr($Line, 127, 2)), |
|||
'CheckSum' => sha1(md5($Line).$Line), |
|||
); |
|||
} else |
|||
$GPCLine = NULL; |
|||
return($GPCLine); |
|||
} |
|||
} |
|||
?></pre> |
|||
===Třída Fio v fio.php=== |
|||
<pre><?php |
|||
include('gpc.php'); |
|||
class Fio |
|||
{ |
|||
var $UserName; |
|||
var $Password; |
|||
var $Account; |
|||
function Import($TimeFrom, $TimeTo) |
|||
{ |
|||
$fp = fsockopen('ssl://www.fio.cz', 443, $errno, $errstr, 30); |
|||
if(!$fp) |
|||
{ |
|||
throw new Exception('Connection error'); |
|||
} else |
|||
{ |
|||
// Send request |
|||
$RequestURL = "/scgi-bin/hermes/dz-pohyby.cgi?ID_ucet=".$this->Account. |
|||
"&LOGIN_USERNAME=".$this->UserName."&SUBMIT=Odeslat&LOGIN_TIME=".time(). |
|||
"&LOGIN_PASSWORD=".$this->Password."&pohyby_DAT_od=".date('d.m.Y', $TimeFrom). |
|||
"&pohyby_DAT_do=".date('d.m.Y', $TimeTo)."&export_gpc=1"; |
|||
$Request = "GET ".$RequestURL." HTTP/1.1\r\n"; |
|||
$Request .= "Host: www.fio.cz\r\n"; |
|||
$Request .= "User-Agent: PHP Script\r\n"; |
|||
$Request .= "Content-Type: text/html\r\n"; |
|||
$Request .= "Connection: Close\r\n\r\n"; |
|||
fwrite($fp, $Request); |
|||
// Read response |
|||
$Response = array(); |
|||
while(!feof($fp)) |
|||
{ |
|||
$Response[] = trim(fgets($fp, 1024)); |
|||
} |
|||
fclose($fp); |
|||
// Strip HTTP header |
|||
while($Response[0] != '') array_shift($Response); |
|||
// Parse all GPC lines |
|||
$GPC = new GPC(); |
|||
$Result = array(); |
|||
foreach($Response as $Line) |
|||
{ |
|||
$GPCLine = $GPC->ParseLine($Line); |
|||
if($GPCLine != NULL) $Result[] = $GPCLine; |
|||
} |
|||
return($Result); |
|||
} |
|||
} |
|||
} |
|||
?></pre> |
|||
===Ukázka použití=== |
|||
<pre><?php |
|||
include('fio.php'); |
|||
$Fio = new Fio(); |
|||
$Fio->Account = '123456789'; |
|||
$Fio->UserName = 'jméno'; |
|||
$Fio->Password = 'heslo'; |
|||
print_r($Fio->Import(time() - 3600 * 24 * 31 * 2, time())); |
|||
?></pre> |
|||
==Vnější odkazy== |
==Vnější odkazy== |
||
Verze z 3. 1. 2011, 20:58
Ukázkové soubory[editovat]
Třída GPC v gpc.php[editovat]
<?php
define('GPC_TYPE_REPORT', '074');
define('GPC_TYPE_ITEM', '075');
class GPC
{
function substr($inputstring, $start, $count)
{
return(substr($inputstring, $start - 1, $count));
}
function ParseLine($Line)
{
$Line = ' '.$Line;
$Type = substr($Line, 1, 3);
if($Type == GPC_TYPE_REPORT)
{
$GPCLine = array
(
'Type' => GPC_TYPE_REPORT,
'AccountNumber' => substr($Line, 4, 16),
'AccountName' => trim(substr($Line, 20, 20)),
'OldBalanceDate' => mktime(0, 0, 0, substr($Line, 42, 2), substr($Line, 40, 2), '20'.substr($Line, 44, 2)),
'OldBalanceValue' => (substr($Line, 60, 1).substr($Line, 46, 14)) / 100,
'NewBalanceValue' => (substr($Line, 75, 1).substr($Line, 61, 14)) / 100,
'DebitValue' => (substr($Line, 90, 1).substr($Line, 76, 14)) / 100,
'CreditValue' => (substr($Line, 105, 1).substr($Line, 91, 14)) / 100,
'SequenceNumber' => intval(substr($Line, 106, 3)),
'Date' => mktime(0, 0, 0, substr($Line, 111, 2), substr($Line, 109, 2), '20'.substr($Line, 113, 2)),
//'DataAlignment' => substr($Line, 115, 14),
'CheckSum' => sha1(md5($Line).$Line),
);
} else
if($Type == GPC_TYPE_ITEM)
{
$GPCLine = array
(
'Type' => GPC_TYPE_ITEM,
'AccountNumber' => substr($Line, 4, 16),
'OffsetAccount' => substr($Line, 20, 16),
'RecordNumber' => substr($Line, 36, 13),
'Value' => substr($Line, 49, 12) / 100,
'Code' => substr($Line, 61, 1),
'VariableSymbol' => intval(substr($Line, 62, 10)),
'BankCode' => substr($Line, 74, 4),
'ConstantSymbol' => intval(substr($Line, 78, 4)),
'SpecificSymbol' => intval(substr($Line, 82, 10)),
'Valut' => substr($Line, 92, 6),
'ClientName' => substr($Line, 98, 20),
//'Zero' => substr($Line, 118, 1),
'CurrencyCode' => substr($Line, 119, 4),
'DueDate' => mktime(0, 0, 0, substr($Line, 125, 2), substr($Line, 123, 2), substr($Line, 127, 2)),
'CheckSum' => sha1(md5($Line).$Line),
);
} else
$GPCLine = NULL;
return($GPCLine);
}
}
?>
Třída Fio v fio.php[editovat]
<?php
include('gpc.php');
class Fio
{
var $UserName;
var $Password;
var $Account;
function Import($TimeFrom, $TimeTo)
{
$fp = fsockopen('ssl://www.fio.cz', 443, $errno, $errstr, 30);
if(!$fp)
{
throw new Exception('Connection error');
} else
{
// Send request
$RequestURL = "/scgi-bin/hermes/dz-pohyby.cgi?ID_ucet=".$this->Account.
"&LOGIN_USERNAME=".$this->UserName."&SUBMIT=Odeslat&LOGIN_TIME=".time().
"&LOGIN_PASSWORD=".$this->Password."&pohyby_DAT_od=".date('d.m.Y', $TimeFrom).
"&pohyby_DAT_do=".date('d.m.Y', $TimeTo)."&export_gpc=1";
$Request = "GET ".$RequestURL." HTTP/1.1\r\n";
$Request .= "Host: www.fio.cz\r\n";
$Request .= "User-Agent: PHP Script\r\n";
$Request .= "Content-Type: text/html\r\n";
$Request .= "Connection: Close\r\n\r\n";
fwrite($fp, $Request);
// Read response
$Response = array();
while(!feof($fp))
{
$Response[] = trim(fgets($fp, 1024));
}
fclose($fp);
// Strip HTTP header
while($Response[0] != '') array_shift($Response);
// Parse all GPC lines
$GPC = new GPC();
$Result = array();
foreach($Response as $Line)
{
$GPCLine = $GPC->ParseLine($Line);
if($GPCLine != NULL) $Result[] = $GPCLine;
}
return($Result);
}
}
}
?>
Ukázka použití[editovat]
<?php
include('fio.php');
$Fio = new Fio();
$Fio->Account = '123456789';
$Fio->UserName = 'jméno';
$Fio->Password = 'heslo';
print_r($Fio->Import(time() - 3600 * 24 * 31 * 2, time()));
?>