devcapere / ofxparser
简单的OFX文件解析器
dev-master
2024-07-17 15:08 UTC
Requires
- php: ~5.6|~7.0|~8.0
Requires (Dev)
- phpunit/phpunit: ~5.5
- squizlabs/php_codesniffer: ~2.6
This package is auto-updated.
Last update: 2024-09-17 15:34:02 UTC
README
OFX解析器是一个PHP库,旨在将金融机构下载的OFX文件解析成简单的PHP对象。
它支持多个银行账户、所需的“登录”响应,并识别OFX时间戳。
安装
使用Composer简单要求此包
$ composer require asgrim/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) { // ... } } }
分支 & 信用
这是一个分支grimfor/ofxparser,旨在实现框架无关性。源存储库是为Symfony 2框架设计的,因此应该给予应有的信用!由Oliver Lowe重写,并基于Andrew A. Smith的Ruby ofx-parser。