mehmetcoban / ofxparser
简单的OFX文件解析器
1.0.2
2022-05-23 11:47 UTC
Requires
- php: ~5.6 || ~8.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.13
- phpunit/phpunit: ~5.5
- squizlabs/php_codesniffer: ~2.6
This package is auto-updated.
Last update: 2024-09-14 01:20:45 UTC
README
OFX解析器是一个PHP库,用于将金融机构下载的OFX文件解析成简单的PHP对象。
它支持多个银行账户、所需的“登录”响应,并识别OFX时间戳。
安装
只需使用 Composer 引入此包即可
$ composer require mehmetcoban/ofxparser
使用方法
您可以通过以下方式访问您的OFX文件中的节点
$ofxParser = new \OfxParser\Parser(); $ofx = $ofxParser->loadFromFile('/path/to/your/bankstatement.ofx'); $bankAccount = reset($ofx->bankAccounts); // Get the statement start and end dates $startDate = $bankAccount->statement->startDate; $endDate = $bankAccount->statement->endDate; // Get the statement transactions for the account $transactions = $bankAccount->statement->transactions;
最常见的节点是支持。如果您在OFX文件中遇到无法访问的节点,请提交一个pull request!
投资支持
与银行/信用卡交易相比,投资看起来大不相同。此版本根据作者的即时需求,支持OFX 2.0.3规范中的一部分节点。如果您选择实现此库,可能需要参考OFX文档。特别是,此版本目前不处理投资头寸(INVPOSLIST)或引用证券定义(SECINFO)。
这并不是一个纯粹的字段传递,如python中的此实现: csingley/ofxtools。此包包含偶尔被“翻译”的字段,使其对不太熟悉投资OFX规范的用户更加友好。
从Quicken(QFX)文件或MS Money(OFX / XML)文件加载投资
// You'll probably want to alias the namespace: use OfxParser\Entities\Investment as InvEntities; // Load the OFX file $ofxParser = new \OfxParser\Parsers\Investment(); $ofx = $ofxParser->loadFromFile('/path/to/your/investments_file.ofx'); // Loop over investment accounts (named bankAccounts from base lib) foreach ($ofx->bankAccounts as $accountData) { // Loop over transactions foreach ($accountData->statement->transactions as $ofxEntity) { // Keep in mind... not all properties are inherited for all transaction types... // Maybe you'll want to do something based on the transaction properties: $nodeName = $ofxEntity->nodeName; if ($nodeName == 'BUYSTOCK') { // @see OfxParser\Entities\Investment\Transaction... $amount = abs($ofxEntity->total); $cusip = $ofxEntity->securityId; // ... } // Maybe you'll want to do something based on the entity: if ($ofxEntity instanceof InvEntities\Transaction\BuyStock) { // ... } } }
Fork & Credits
这是对 asgrim/ofxparser 的fork,而asgrim/ofxparser又是 grimfor/ofxparser 的fork,旨在实现框架无关性。源存储库是为Symfony 2框架设计的,因此应给予适当的信用!由 Oliver Lowe 重构,并松散地基于Andrew A. Smith的ruby ofx-parser。