我需要幫助我的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;
}
?>
是'|'本該是文字上的' |'人物?所以你需要將你的變量和'|'和一個salt連接起來,並把結果字符串通過sha512?不能那麼難,你到底有什麼問題? – deceze 2012-08-02 06:35:54
另外,SHA512!==「加密」。這是一個*哈希*! – deceze 2012-08-02 06:36:40
Tx用於您的建議和更正。 – user1570503 2012-08-02 08:03:51