Skip to content

Cálculo Cids em PHP funcionando #51

@emersonrf227

Description

@emersonrf227
<?php

namespace App\sts\Controllers;

if (!defined('URL')) {
  header("Location: /");
  exit();
}

class Reconciliacao
{

  private $Dados;




  function stringGuidAsBinaryGuid($stringGuid)
  {
    $binary = pack("H*", str_replace('-', '', $stringGuid));
    return $binary;
  }

  function binaryGuidAsStringGuid($binaryGuid)
  {
    $string = unpack("H*", $binaryGuid);
    $string = preg_replace(
      "/([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})/",
      "$1-$2-$3-$4-$5",
      $string["1"]
    );
    return $string;
  }

  public function calc()
  {

    //Dados necessários para pegar o montar o CID 
    $type = "EMAIL";
    $email = "[email protected]";
    $ownerTaxIdNumber = "51857504488";
    $ownerName = "Andreia Oliveira Almeida";
    $ownerTradeName = "";
    $participant = "yourNumber";
    $branch = "0002";
    $accountNumber = "170888053967579";
    $accountType = "CACC";
    $entryAttributes =  "$type&$email&$ownerTaxIdNumber&$ownerName&$ownerTradeName&$participant&$branch&$accountNumber&$accountType";
    $requestIdBytes = "670032e7-e4b6-4f60-8a30-bdcd30ca971f";
    $bin = $this->stringGuidAsBinaryGuid($requestIdBytes);
    $cidBytes = hash_hmac('sha256', $entryAttributes, $bin, false );
    // variavel cidBytes contém o resultado do cid; 

    
    // o exemplo abaixo mostra como montar o calculo de cid`s com bitwise em Xor os cid's abaixo temos     
    // exemplos de cid's forncecidos na doc documentação do banco central onde o objetivo foi chegar no resultado do exemplo da doc
    // https://gokeitecnologia.com.br/api-docs/SPI/DICT/#section/Calculo-de-CID
    // na documentação o resultado esperado tem que ser igual a 996fc1dd3b6b14bcf0c9fe8320eb66d7e2a3fd874ccf767b2e939641b1ea8eaf


    $cidP1 = $this->stringGuidAsBinaryGuid('28c06eb41c4dc9c3ae114831efcac7446c8747777fca8b145ecd31ff8480ae88');
    $cidP2 = $this->stringGuidAsBinaryGuid('4d4abb9168114e349672b934d16ed201a919cb49e28b7f66a240e62c92ee007f');
    $cidP3 = $this->stringGuidAsBinaryGuid('fce514f84f37934bc8aa0f861e4f7392273d71b9d18e8209d21e4192a7842058');
    $x = $cidP1 ^ $cidP2 ^ $cidP3;
    echo str_replace("-", "", $this->binaryGuidAsStringGuid($x));
 
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions