Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

600
Views
Cómo crear y analizar etiquetas, longitudes y valores (TLV) en PHP y codificarlos en Base64

Hay una nueva regulación del Gobierno que solicita a todas las empresas registradas de IVA que implementen el CÓDIGO QR en la nueva factura electrónica.

  • Los campos de código QR se codificarán en formato Tag-Length-Value (TLV) con los valores de etiqueta especificados en la columna "Etiqueta" de la tabla adyacente.

  • La codificación TLV será la siguiente:

    • Etiqueta: el valor de la etiqueta como se mencionó anteriormente almacenado en un byte.
    • Longitud: la longitud de la matriz de bytes resultante de la codificación UTF8 del valor del campo. La longitud se almacenará en un byte.
    • Valor: la matriz de bytes resultante de la codificación UTF8 del valor del campo.

¿Cómo creo TLV a partir de una matriz de información? ¿Hay una biblioteca que pueda usar?

 $arr = [ 1 => 'Company Name', 2 => '1234567890', 3 => '2021/10/11 17:20:00', 4 => '1000', 5 => '150' ];
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Sí, el código QR requerido no es un código QR normal con un enlace. Debe estar codificado en TLV base64. Se puede hacer muy fácilmente. los valores deben ser hexadecimales y luego combinados, lo que contendrá caracteres de control ASCII.

Si aún no lo obtiene, afortunadamente, puede usar el siguiente paquete de Salla para generar un código QR desde la matriz.

https://github.com/SallaApp/ZATCA

Asegúrese de seguir la estructura de etiquetas proporcionada por la ZATCA (GAZT anteriormente). El ejemplo del paquete tiene la matriz correcta:

 $generatedString = GenerateQrCode::fromArray([ new Seller('Salla'), // seller name new TaxNumber('1234567891'), // seller tax number new InvoiceDate('2021-07-12T14:25:09Z'), // invoice date as Zulu ISO8601 @see https://en.wikipedia.org/wiki/ISO_8601 new InvoiceTotalAmount('100.00'), // invoice total amount new InvoiceTaxAmount('15.00') // invoice tax amount // TODO :: Support others tags ])->toTLV();
over 4 years ago · Santiago Trujillo Report

0

Para aquellos que todavía usan php5 basado en https://github.com/SallaApp/ZATCA

 /* * QR Encoding Functions */ function __getLength($value) { return strlen($value); } function __toHex($value) { return pack("H*", sprintf("%02X", $value)); } function __toString($__tag, $__value, $__length) { $value = (string) $__value; return __toHex($__tag) . __toHex($__length) . $value; } function __getTLV($dataToEncode) { $__TLVS = ''; for ($i = 0; $i < count($dataToEncode); $i++) { $__tag = $dataToEncode[$i][0]; $__value = $dataToEncode[$i][1]; $__length = __getLength($__value); $__TLVS .= __toString($__tag, $__value, $__length); } return $__TLVS; } /* * QR Encoding Functions */ /* * QR Code */ $dataToEncode = [ [1, 'SellerName'], [2, 'VATNumber'], [3, 'invoiceDatetime'], [4, 'AmtwithVAT'], [5, 'VATamt'] ]; $__TLV = __getTLV($dataToEncode); $__QR = base64_encode($__TLV); echo $__QR; /* * QR Code */

1-- Instalar ZATCA SDK https://zatca.gov.sa/en/E-Invoicing/SystemsDevelopers/ComplianceEnablementToolbox/Pages/DownloadSDK.aspx

2 -- fatoorah validarqr -qr "$__QR"

over 4 years ago · Santiago Trujillo Report

0

function einv_generate_tlv_qr_code($array_tag=array()){ $index=1; foreach($array_tag as $tag_val){ $tlv_string.=pack("H*", sprintf("%02X",(string) "$index")). pack("H*", sprintf("%02X",strlen((string) "$tag_val"))). (string) "$tag_val"; $index++; } return base64_encode($tlv_string); }

Simplemente envíele valores de etiquetas en matriz a la función y le devolverá el contenido TLV de QRcode

 $data_tlv=einv_generate_tlv_qr_code(array($company_name,$vat_reference,$timestamp,$total,$vat);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!