在添加用户定义的字段时,Payumoney中出现CheckSum错误,尽管在添加之前定义完美。
我一直在当实习生,我的员工要求我建立一个支付网关。我以前工作过,但是在添加两个用户定义的字段时,它开始给我一个校验和错误。
<?php
$MERCHANT_KEY = "Key";
$SALT = "Salt";
// Merchant Key and Salt as provided by Payu.
$PAYU_BASE_URL = "https://sandboxsecure.payu.in"; // For Sandbox Mode
//$PAYU_BASE_URL = "https://secure.payu.in"; // For Production Mode
$succesURL="Success URL";
$failureURL="Fail URL";
$action = '';
$posted = array();
if(!empty($_POST)) {
//print_r($_POST);
foreach($_POST as $key => $value) {
$posted[$key] = $value;
}
}
$formError = 0;
if(empty($posted['txnid'])) {
// Generate random transaction id
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
} else {
$txnid = $posted['txnid'];
}
$hash = '';
// Hash Sequence
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty($posted['hash']) && sizeof($posted) > 0) {
if(
empty($posted['key'])
|| empty($posted['txnid'])
|| empty($posted['amount'])
|| empty($posted['firstname'])
|| empty($posted['email'])
|| empty($posted['phone'])
|| empty($posted['productinfo'])
|| empty($posted['surl'])
|| empty($posted['furl'])
|| empty($posted['service_provider'])
) {
$formError = 1;
} else {
//$posted['productinfo'] = json_encode(json_decode('[{"name":"tutionfee","description":"","value":"500","isRequired":"false"},{"name":"developmentfee","description":"monthly tution fee","value":"1500","isRequired":"false"}]'));
$hashVarsSeq = explode('|', $hashSequence);
$hash_string = '';
foreach($hashVarsSeq as $hash_var) {
$hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
$hash_string .= '|';
}
$hash_string .= $SALT;
$hash = strtolower(hash('sha512', $hash_string));
$action = $PAYU_BASE_URL . '/_payment';
}
} elseif(!empty($posted['hash'])) {
$hash = $posted['hash'];
$action = $PAYU_BASE_URL . '/_payment';
}
?>
<html>
<head>
<script>
var hash = '<?php echo $hash ?>';
function submitPayuForm() {
if(hash == '') {
return;
}
var payuForm = document.forms.payuForm;
payuForm.submit();
}
</script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body onload="submitPayuForm()" style="background-color:#35f5bc">
<div class="container mt-5">
<img src="p.jpeg" alt="">
</div>
<br/>
<?php if($formError) { ?>
<span style="color:red">Please fill all mandatory fields.</span>
<br/>
<br/>
<?php } ?>
<div class="container rounded mt-5 bg-white shadow-lg px-3 py-5" style="width:450px">
<form action="<?php echo $action; ?>" method="post" name="payuForm">
<input type="hidden" name="key" value="<?php echo $MERCHANT_KEY ?>" />
<input type="hidden" name="hash" value="<?php echo $hash ?>"/>
<input type="hidden" name="txnid" value="<?php echo $txnid ?>" />
<div class="form-group">
<div>Amount: </div>
<input class="form-control" name="amount" value="<?php echo (empty($posted['amount'])) ? '2000' : $posted['amount'] ?>" readonly />
<div>First Name: </div>
<input class="form-control" name="firstname" id="firstname" value="<?php echo (empty($posted['firstname'])) ? '' : $posted['firstname']; ?>" readonly/>
</div>
<div class="form-group">
<div>Email: </div>
<input class="form-control" name="email" id="email" value="<?php echo (empty($posted['email'])) ? '' : $posted['email']; ?>" readonly/>
<div>Phone: </div>
<input class="form-control" name="phone" value="<?php echo (empty($posted['phone'])) ? '' : $posted['phone']; ?>" readonly/>
</div>
<div class="form-group">
<div>Product Info: </div>
<textarea readonly class="form-control" name="productinfo"><?php echo (empty($posted['productinfo'])) ? '' : $posted['productinfo'] ?></textarea>
<input type="hidden" name="udf1" value="<?php echo $posted['course_type']; ?>"/>
<input type="hidden" name="udf2" value="<?php echo $posted['subject']; ?>"/>
</div>
<div>
<input type="hidden" name="surl" value="<?php echo $succesURL; ?>" size="64" />
<input type="hidden" name="furl" value="<?php echo $failureURL; ?>" size="64" />
</div>
<div>
<div ><input type="hidden" name="service_provider" value="payu_paisa" size="64" /></div>
</div>
<?php if(!$hash) { ?>
<div><input class="btn btn-primary" type="submit" value="Submit" /></div>
<?php } ?>
</form>
</div>
</body>
</html>
预期:成功的工作付款准备金。 实际:CheckSum错误