2012-08-02 47 views
2

我需要幫助我的PHP腳本。我需要以加密方式發佈特定字段,如invoiceid,firstname,email等。校驗公式爲如何發佈sha512加密數據

sha512 (key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||<SALT>) 

我需要通過sha512發佈上述變量。我無法做到這一點。請幫助。我是一名學習者,而且我不擅長PHP。

這是代碼。我仍然得到校驗錯誤。

<?php 
function xxx_config() { 

    $configarray = array(
    "FriendlyName" => array("Type" => "System", "Value"=>"XXX"), 
    "alias" => array("FriendlyName" => "Merchant ID", "Type" => "text", "Size" => "20",), 
    "salt" => array("FriendlyName" => "SALT", "Type" => "text", "Size" => "20",), 
    "mode" => array("FriendlyName" => "MODE", "Type" => "text", "Description" => "TEST or LIVE",), 

    ); 
    return $configarray; 
} 

function xxx_link($params) { 


    # Gateway Specific Variables 
    $key = $params['alias']; 
    $gatewaymode = $params['mode']; 
    $salt = $params['salt']; 


    # Invoice Variables 
    $txnid = $params['invoiceid']; 
    $productinfo = $params["description"]; 
    $amount = $params['amount']; # Format: ##.## 
    $currency = $params['currency']; # Currency Code 

    # Client Variables 
    $firstname = $params['clientdetails']['firstname']; 
    $lastname = $params['clientdetails']['lastname']; 
    $email = $params['clientdetails']['email']; 
    $address1 = $params['clientdetails']['address1']; 
    $address2 = $params['clientdetails']['address2']; 
    $city = $params['clientdetails']['city']; 
    $state = $params['clientdetails']['state']; 
    $postcode = $params['clientdetails']['postcode']; 
    $country = $params['clientdetails']['country']; 
    $phone = $params['clientdetails']['phonenumber']; 

    # System Variables 
    $companyname = 'XXX'; 
    $systemurl = $params['systemurl']; 
    $currency = $params['currency']; 

     # Enter your code submit to the gateway... 

$hashdata = ($key."|".$txnid."|".$amount."|".$productinfo."|".$firstname."|".$email."|"."|"."|"."|"."|"."|".$salt); 

    $hash = hash("sha512", $hashdata); 

$code = '<form method="post" action="https://secure.xxx.xxx" name="frmTransaction" id="frmTransaction" onSubmit="return validate()"> 
<input type="hidden" name="key" value="'.$key.'" /> 
<input type="hidden" name="mode" value="'.$gatewaymode.'" /> 
<input type="hidden" name="productinfo" value="'.$productinfo.'" /> 
<input type="hidden" name="txnid" value="'.$txnid.'" /> 
<input type="hidden" name="salt" value="'.$salt.'" /> 
<input type="hidden" name="name" value="'.$firstname.'" /> 
<input type="hidden" name="address" value="'.$address1.'" /> 
<input type="hidden" name="city" value="'.$city.'" /> 
<input type="hidden" name="state" value="'.$state.'" /> 
<input type="hidden" name="country" value="'.$country.'" /> 
<input type="hidden" name="postal_code" value="'.$postcode.'" /> 
<input type="hidden" name="ship_name" value="'.$firstname.'" /> 
<input type="hidden" name="ship_address" value="'.$address1.'" /> 
<input type="hidden" name="ship_city" value="'.$city.'" /> 
<input type="hidden" name="ship_state" value="'.$state.'" /> 
<input type="hidden" name="ship_country" value="'.$country.'" /> 
<input type="hidden" name="ship_postal_code" value="'.$postcode.'" /> 
<input type="hidden" name="ship_phone" value="'.$phone.'" /> 
<input type="hidden" name="email" value="'.$email.'" /> 
<input type="hidden" name="phone" value="'.$phone.'" /> 
<input type="hidden" name="amount" value="'.$amount.'" /> 
<input type="hidden" name="surl" value="https://xxx.xx/xxxx.php" /> 
<input type="hidden" name="furl" value="https://xxx.xx/xxx.php" /> 
<input type="hidden" name="Hash" value="'.$hash.'"/> 
<input type="submit" value="Pay Now" /> 
</form>'; 

return $code; 

} 
?> 
+1

是'|'本該是文字上的' |'人物?所以你需要將你的變量和'|'和一個salt連接起來,並把結果字符串通過sha512?不能那麼難,你到底有什麼問題? – deceze 2012-08-02 06:35:54

+2

另外,SHA512!==「加密」。這是一個*哈希*! – deceze 2012-08-02 06:36:40

+0

Tx用於您的建議和更正。 – user1570503 2012-08-02 08:03:51

回答

1

hash()函數是你在找什麼。要創建SHA512哈希如下稱之爲:

hash('sha512', "the value to hash"); 

看到哈希算法你還能用什麼來看看在hash_algos()函數

+0

你的公式是正確的,但根據它們的公式,所有值(如txnid,name等)應該用sha512算法(即sha512(值))加密或散列,但上述公式不會這樣做。請幫助另一種方法。 – user1570503 2012-08-03 14:34:57

+0

是否要將每個值(txnid)與'|'連接在一起,然後將它們全部散列在一起,或者是否希望散列每個值然後連接它? – MarcDefiant 2012-08-06 06:30:46

+0

用|表示每個值然後散列它。在上面的公式中,如果字段爲空,那麼它應該爲每個字段攜帶一個PIP。就像如果我沒有在上述公式中使用udf,那麼我已經用一個管道取代了這個,即總共有11個管道應該到來。 – user1570503 2012-08-06 08:44:23