生成银行交易的唯一密钥

时间:2016-10-19 10:02:23

标签: php algorithm banking

我想通过HBCI持续导入银行交易。 问题是,那些既没有唯一的密钥,也没有精确的时间戳(时间戳只在日期分辨率上,即总是在上午12点)。

这是我从API获得的数据

enter image description here

在所有字段上生成哈希会导致误报(如果某人在同一天使用相同的目的文本传输相同的值,依此类推)

如何避免重复导入并生成唯一键?

1 个答案:

答案 0 :(得分:0)

/**
 * Generate a unique ID per transaction
 * We assume, that all transactions of a day are always present in the fetched transactions
 * (after a while, very old transactions might not appear)
 * So we generate a continues key per day, combine it with the date and have a globally unique key
 *
 * @return Transaction[]
 */
public static function getKeyedTransactions()
{
    $transactions = self::getTransactions();
    $result = [];
    $dateCounters = array();
    foreach($transactions as $transaction) {
        $date = $transaction->getDate()->format('Ymd');
        if (!isset($dateCounters[$date])) {
            $dateCounters[$date] = 0;
        }
        $dateCounters[$date]++;
        $uniqId = $date . sprintf('%05d', $dateCounters[$date]);
        $result[$uniqId] = $transaction;
    }
    return $result;
}