4

我使用了三个变量,它们从 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);

        ?>
4

1 回答 1

0

vpc_ReturnURL应该是实时服务器,而不是您的localhost,万事达卡(或贝宝等)无法访问您的本地主机并发布数据。


您可能会如何看到 400 错误:

“400 错误请求”

“错误请求。您的浏览器发送了此服务器无法理解的请求。”

“错误请求 - 无效 URL”

“HTTP 错误 400 - 错误请求”

“错误请求:错误 400”

“HTTP 错误 400。请求主机名无效。”

“400 - 错误请求。由于语法错误,服务器无法理解请求。客户端不应在未修改的情况下重复请求。”

于 2016-03-21T10:46:53.580 回答