Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cálculo Cids em PHP funcionando #51

Open
emersonrf227 opened this issue Jan 9, 2023 · 0 comments
Open

Cálculo Cids em PHP funcionando #51

emersonrf227 opened this issue Jan 9, 2023 · 0 comments

Comments

@emersonrf227
Copy link

emersonrf227 commented Jan 9, 2023

<?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 = "client0454@iliketechnology.com.br";
    $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));
 
  }
}

@emersonrf227 emersonrf227 changed the title Exemplo em php para que precisar. Calculo Cids em PHP funcionando Jan 9, 2023
@emersonrf227 emersonrf227 changed the title Calculo Cids em PHP funcionando Cálculo Cids em PHP funcionando Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant