对于那些仍在使用基于 https://github.com/SallaApp/ZATCA的 php5 的人
/*
* 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-- 安装 ZATCA SDK
https://zatca.gov.sa/en/E-Invoicing/SystemsDevelopers/ComplianceEnablementToolbox/Pages/DownloadSDK.aspx
2 -- fatoorah validateqr -qr "$__QR"