万事达卡支付集成服务无法在PHP中运行

时间:2016-03-21 10:23:25

标签: php mastercard

我使用了从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);

        ?>

1 个答案:

答案 0 :(得分:0)

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

您可能会看到400错误:

“400 Bad Request”

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

“错误请求 - 无效网址”

“HTTP错误400 - 错误请求”

“错误请求:错误400”

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

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