我使用了三个变量,它们从 html 中发布并传入 $postdata 数组
$cardnum= $_POST['Card_Num'];
$cardexp= $_POST['Card_Exp'];
$amount =$_POST['amount'];
在 $postdata 数组中传递这三个变量
$postdata = array(
"vpc_CardNum" => $cardnum,
"vpc_CardExp" => $cardexp,
"vpc_AccessCode" => $accessCode,
"vpc_Amount" => ($amount*100),
"vpc_Command" => 'pay',
"vpc_Locale" => 'en',
"vpc_MerchTxnRef" => $unique_id,
"vpc_Merchant" => $merchantId,
"vpc_OrderInfo" => 'this is a product',
"vpc_ReturnURL" => "https://localhost/success.php",
"vpc_Version" => '1');
完整的代码在下面给出了html: -
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form method="POST" action="integrate.php">
Credit Card Number
<input type="text" name="Card_Num">
<input type="text" name="Card_Exp" maxlength="4">
<input type="number" name="amount">
<input type="submit" value="Submit payment">
</form
</body>
</html>
下面给出了完整的 php 代码,它给出了 400 错误的状态
<?php
$cardnum= $_POST['Card_Num'];
$cardexp= $_POST['Card_Exp'];
$amount =$_POST['amount'];
$SECURE_SECRET = "YEOCOEN29B0785F1FF1E3C0FA8A3FUJK";
$accessCode = '546484645';
$merchantId = 'ABERCROMBIEKIDS#119GARDENCITYNY';
$cardnum= $_POST['Card_Num'];
$cardexp= $_POST['Card_Exp'];
$amount =$_POST['amount'];
$unique_id = rand(999999,8988888888);//this is a sample random no
$postdata = array(
"vpc_CardNum" => $cardnum,
"vpc_CardExp" => $cardexp,
"vpc_AccessCode" => $accessCode,
"vpc_Amount" => ($amount*100),
"vpc_Command" => 'pay',
"vpc_Locale" => 'en',
"vpc_MerchTxnRef" => $unique_id,
"vpc_Merchant" => $merchantId,
"vpc_OrderInfo" => 'this is a product',
"vpc_ReturnURL" => "https://localhost/success.php",
"vpc_Version" => '1');
$vpcURL = 'https://migs.mastercard.com.au/vpcpay?';
$md5Hash = $SECURE_SECRET;
$appendAmp = 0;
foreach ($postdata as $key => $value) {
if (strlen($value) > 0) {
if ($appendAmp == 0) {
$vpcURL .= urlencode($key) . '=' . urlencode($value);
$appendAmp = 1;
} else {
$vpcURL .= '&' . urlencode($key) . "=" . urlencode($value);
}
$md5Hash .= $value;
}
}
var_dump($postdata);
print_r($postdata);
if (strlen($SECURE_SECRET) > 0) {
$vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($md5Hash));
}
header("Location: " . $vpcURL);
?>