我的PHP脚本需要帮助。我需要以加密的方式发布某些字段,如invoiceid,firstname,email等。校验和的公式是
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;
}
?>
答案 0 :(得分:1)
你正在寻找hash()函数。要创建sha512哈希,请按如下方式调用它:
hash('sha512', "the value to hash");
查看您可以使用的其他哈希算法,看一下hash_algos()函数