jacques/ofxparser

简单的 OFX 文件解析器

1.2.2 2018-10-29 10:10 UTC

This package is auto-updated.

Last update: 2024-09-07 22:38:58 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version License

OFX 解析器是一个 PHP 库,用于将来自金融机构下载的 OFX 文件解析成简单的 PHP 对象。

它支持多个银行账户、所需的“登录”响应,并识别 OFX 时间戳。

安装

只需使用 Composer 引入此包

$ composer require jacques/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) {
            // ...
        }

    }
}

分支 & 贡献

这是asgrim/ofxparser的一个分支,后者是grimfor/ofxparser的一个分支,旨在成为框架无关的。源代码仓库是为 Symfony 2 框架设计的,因此应给予应有的认可!由 Oliver Lowe 重构,并松散地基于 ruby 的 ofx-parser by Andrew A. Smith