test.php 1.55 KB
<?php

function unpackage($queryString) {
    $array = array();
    parse_str($queryString, $array);

    return $array;
}

$stringQuery = 'a1=4&A2=4';
$values = unpackage($stringQuery);

function package($values, $SecureHash, &$arrayRequestKey) {
    $queryString = '';
    //$hashData    = $SecureHash;
    // 1. The Secure Hash Secret is always first.
    // 2. Then all DO fields are concatenated to the Secure Hash Secret in alphabetical order of the field name.
    ksort($values);

    foreach ($values as $key => $val) {
        if (strlen($val) > 0) {
            $queryString .= $key . '=' . rawurlencode($val) . '&';
            //$hashData .= $val;
            $arrayRequestKey[] = $key;
        }
    }

    // Remove the trailing '&'.
    $queryString = substr($queryString, 0, strlen($queryString) - 1);

    // Create the secure hash and append it if the merchant secret has been provided.
    if (strlen($SecureHash) > 0) {
        $stringSecureHash = strtoupper(hash_hmac('SHA256', $queryString, pack('H*', $SecureHash)));
        //strtoupper(md5($hashData)) 

        $queryString = 'vpc_SecureHash=' . $stringSecureHash . '&vpc_SecureHashType=SHA256' . '&' . $queryString;
    }

    return $queryString;
}

$arrayRequestKey = array();
echo package($values, '123454567', $arrayRequestKey);
print_r($arrayRequestKey);


exit();
echo date('d-m-Y H:i:s');
exit();
echo dirname(__FILE__);
exit();
echo (extension_loaded('xdebug') ? '' : 'non '), 'exists';
ini_set('memory_limit', '256M');
phpinfo();
exit();
print_r($_SERVER);
echo dirname(__FILE__);
echo "Test trest";