解析 ofx 請求響應

OFX,Open Financial Exchange,文件用於交換財務信息。它用於客戶端-服務器以及基於雲的系統。因此,請求-響應模型用於交換財務信息。讓我們了解一下 OFX 請求和響應:

解析 OFX 請求和響應——C# API 安裝

Aspose.Finance for .NET API 支持多種處理和解析財務數據的功能。您可以從 下載 部分下載它,或使用以下命令通過 NuGet 庫進行安裝:

PM> Install-Package Aspose.Finance

此外,OFX 的演變在這裡值得一提。 OFX 版本 1 到 1.6 基於 SGML 語法。以後的版本依賴於 XML 規範。為了更好地理解,我們將創建兩種格式(1.03 和 2.2)的 OFX 請求和響應文件。

使用 C# 以編程方式創建 OFX 請求

OFX 協議是一種用於金融數據雙向交換的標準。您可以按照以下步驟輕鬆創建請求:

  1. 初始化 Ofx Request Document 對象
  2. 創建 登錄請求 實例
  3. 設置不同的屬性
  4. 以 1.03 和 2.2 格式保存 OFX 請求

下面的代碼片段解釋瞭如何使用 C# 語言以編程方式創建 OFX 請求:

// 初始化 OfxRequestDocument 對象
OfxRequestDocument document = new OfxRequestDocument();
document.SignonRequestMessageSetV1 = new SignonRequestMessageSetV1();

// 初始化 SignonRequest 並設置不同的屬性
SignonRequest signonRequest = new SignonRequest();
document.SignonRequestMessageSetV1.SignonRequest = signonRequest;
signonRequest.ClientDate = "20200611000000";
signonRequest.UserId = "aspose";
signonRequest.UserPassword = "password";
FinancialInstitution fi = new FinancialInstitution();
fi.Organization = "aspose";
fi.FinancialInstitutionId = "1";
signonRequest.FinancialInstitution = fi;
signonRequest.AppVersion = "1.0";
signonRequest.AppId = "Aspose.Finance";
signonRequest.ClientUserId = "aaaaaaa";

document.BankRequestMessageSetV1 = new BankRequestMessageSetV1();
StatementTransactionRequest stmtTransRequest = new StatementTransactionRequest();
document.BankRequestMessageSetV1.StatementTransactionRequests.Add(stmtTransRequest);
stmtTransRequest.TransactionUniqueId = "1111111";
stmtTransRequest.StatementRequest = new StatementRequest();
stmtTransRequest.StatementRequest.BankAccountFrom = new BankAccount();
stmtTransRequest.StatementRequest.BankAccountFrom.BankId = "sssss";
stmtTransRequest.StatementRequest.BankAccountFrom.AccountId = "sfsdfsfsdf";
stmtTransRequest.StatementRequest.BankAccountFrom.AccountType = AccountEnum.CHECKING;
stmtTransRequest.StatementRequest.IncTransaction = new IncTransaction();
stmtTransRequest.StatementRequest.IncTransaction.StartDate = "20200601000000";
stmtTransRequest.StatementRequest.IncTransaction.EndDate = "20200611000000";
stmtTransRequest.StatementRequest.IncTransaction.Include = true;

// 為兩個版本創建 OFX 請求
document.Save(outputDir + @"newOfxRequestBankStatement.xml", OfxVersionEnum.V2x);
document.Save(outputDir + @"newOfxRequestBankStatement.sgml", OfxVersionEnum.V1x);

使用 C# 以編程方式創建 OFX 響應

您可以使用 C# 在基於 .NET 的應用程序中以編程方式創建 OFX 響應。以下步驟解釋了 OFX 響應創建過程:

  1. 初始化 Ofx Response Document 類對象
  2. 聲明 Sign on Response 並設置值
  3. 使用 Ofx Version Enum 枚舉保存響應

以下代碼片段顯示瞭如何使用 C# 以編程方式創建 OFX 響應:

// 初始化 OfxResponseDocument 對象
OfxResponseDocument document = new OfxResponseDocument();
document.SignonResponseMessageSetV1 = new SignonResponseMessageSetV1();

// 初始化 SignonResponse 實例
SignonResponse signonResponse = new SignonResponse();
document.SignonResponseMessageSetV1.SignonResponse = signonResponse;
signonResponse.Status = new Status();
signonResponse.Status.Code = "0";
signonResponse.Status.Severity = SeverityEnum.INFO;
signonResponse.Status.Message = "SUCCESS";
signonResponse.ServerDate = "20200611";
signonResponse.ProfileUpdateDate = "20200611";
FinancialInstitution fi = new FinancialInstitution();
fi.Organization = "aspose";
fi.FinancialInstitutionId = "1";
signonResponse.FinancialInstitution = fi;
signonResponse.SessionCookie = "11111111111111111";

document.BankResponseMessageSetV1 = new BankResponseMessageSetV1();
StatementTransactionResponse stmtTransResponse = new StatementTransactionResponse();
document.BankResponseMessageSetV1.StatementTransactionResponses.Add(stmtTransResponse);
stmtTransResponse.TransactionUniqueId = "829631324";
stmtTransResponse.Status = new Status();
stmtTransResponse.Status.Code = "0";
stmtTransResponse.Status.Severity = SeverityEnum.INFO;
stmtTransResponse.StatementResponse = new StatementResponse();
stmtTransResponse.StatementResponse.Currency = CurrencyEnum.USD;
stmtTransResponse.StatementResponse.BankAccountFrom = new BankAccount();
stmtTransResponse.StatementResponse.BankAccountFrom.BankId = "1111111";
stmtTransResponse.StatementResponse.BankAccountFrom.AccountId = "1111111111111";
stmtTransResponse.StatementResponse.BankAccountFrom.AccountType = AccountEnum.CHECKING;
stmtTransResponse.StatementResponse.BankTransactionList = new BankTransactionList();
stmtTransResponse.StatementResponse.BankTransactionList.StartDate = "20200601000000";
stmtTransResponse.StatementResponse.BankTransactionList.EndDate = "20200611000000";
StatementTransaction transaction1 = new StatementTransaction();
transaction1.TransactionType = TransactionEnum.DEBIT;
transaction1.PostedDate = "20200611000000";
transaction1.TransactionAmount = "-12";
transaction1.FinancialInstitutionTransactionId = "1111111111111111111111111";
transaction1.Name = "bbbbbbbbbbbbbbbbbbbbbbb";
StatementTransaction transaction2 = new StatementTransaction();
transaction2.TransactionType = TransactionEnum.CREDIT;
transaction2.PostedDate = "20200611000000";
transaction2.TransactionAmount = "22222.11";
transaction2.FinancialInstitutionTransactionId = "2222222222222222222222222222";
transaction2.Name = "wwwwwwwwwwwwwwwwwwwwwwww";
stmtTransResponse.StatementResponse.BankTransactionList.StatementTransactions.Add(transaction1);
stmtTransResponse.StatementResponse.BankTransactionList.StatementTransactions.Add(transaction2);
stmtTransResponse.StatementResponse.LedgerBalance = new LedgerBalance();
stmtTransResponse.StatementResponse.LedgerBalance.BalanceAmount = "+2222.42";
stmtTransResponse.StatementResponse.LedgerBalance.DateAsOf = "20200611000000";
stmtTransResponse.StatementResponse.AvailableBalance = new AvailableBalance();
stmtTransResponse.StatementResponse.AvailableBalance.BalanceAmount = "+222222.42";
stmtTransResponse.StatementResponse.AvailableBalance.DateAsOf = "20200611000000";

// 以 OFX 1.03 和 2.2 格式規範保存響應
document.Save(outputDir + @"newOfxResponseBankStatement.xml", OfxVersionEnum.V2x);
document.Save(outputDir + @"newOfxResponseBankStatement.sgml", OfxVersionEnum.V1x);

結論

OFX標準獨立於平台,因此用戶可以選擇系統環境或平台來使用金融處理功能。它使銀行、經紀公司和薪資處理公司能夠創建量身定制的解決方案。您可以通過 免費支持論壇 取得聯繫。我們很樂意為您提供幫助!

也可以看看