贝宝沙盒IPN-未得到验证响应 [英] Paypal Sandbox IPN - Not getting VERIFIED response

查看:91
本文介绍了贝宝沙盒IPN-未得到验证响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我讨厌问一个似乎以前被问过很多次的问题,但是从阅读许多帖子后,我似乎无法弄清楚为什么我没有从贝宝(Paypal)沙箱中收到已验证"消息,我在现在已经几个小时了,而且没有任何进一步的进展.

I hate asking a question which seems to have been asked many times before but from reading many posts I can't seem to figure out why I'm not getting the "VERIFIED" message back from paypal sandbox, I'm at this now several hours now and am not getting any further.

我通过电子邮件将对paypal的验证调用的结果通过电子邮件发送,如下所示,但没有"VERIFIED",我正在使用IPN模拟器进行测试

I email the result of the verify call to paypal, below is what it says, but no "VERIFIED", I'm testing using the IPN Simulator https://developer.paypal.com/webapps/developer/applications/ipn_simulator

找到HTTP/1.0 302 位置: https://www.sandbox.paypal.com 伺服器:BigIP 连接:保持活动 内容长度:0

HTTP/1.0 302 Found Location: https://www.sandbox.paypal.com Server: BigIP Connection: Keep-Alive Content-Length: 0

<?php
    include("connect.php");

    // Send an empty HTTP 200 OK response to acknowledge receipt of the notification
    header('HTTP/1.1 200 OK');

    // Assign payment notification values to local variables
    $item_name        = $_POST['item_name'];
    $item_number      = $_POST['item_number'];
    $payment_status   = $_POST['payment_status'];
    $payment_amount   = $_POST['mc_gross'];
    $payment_currency = $_POST['mc_currency'];
    $payer_email      = $_POST['payer_email'];

    // Build the required acknowledgement message out of the notification just received
    $req = 'cmd=_notify-validate';               // Add 'cmd=_notify-validate' to beginning of the acknowledgement

    $msg = "";
    foreach ($_POST as $key => $value) {         // Loop through the notification NV pairs
        $value = urlencode(stripslashes($value));  // Encode these values
        $req  .= "&$key=$value";                   // Add the NV pairs to the acknowledgement
    }

    $req = "";

    // Set up the acknowledgement request headers
    $header  = "POST /cgi-bin/webscr HTTP/1.1\r\n";                    // HTTP POST request
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

    // Open a socket for the acknowledgement request
    $fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

    // Send the HTTP POST request back to PayPal for validation
    fputs($fp, $header . $req);

    $result = "";
    while (!feof($fp))
    {                     // While not EOF
        $res=fgets($fp, 1024);               // Get the acknowledgement response
        $result .= $res;

        if (strcmp ($res, "VERIFIED") == 0){  // Response contains VERIFIED - process notification
            //db code here
        }
    }

    $to = 'test@email.com';
    $subject = 'Result';
    $m = $result;
    $headers = 'From: admin@email.com'."\r\n".
    'Reply-To: admin@email.com'."\r\n".
    'X-Mailer: PHP/'.phpversion();

    mail($to, $subject, $m, $headers);

    fclose($fp);  // Close the file
?>

推荐答案

除了Matthew的回应外,我还必须添加另一行以将HTTP主机声明为详细的

In addition to Matthew's response, I had to add an additional line to declare the HTTP Host as detailed here:

$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";

我也无法在服务器上使用https://协议,但将其切换到ssl://却对我有用,并详细说明了

Also I wasn't able to get the https:// protocol to work on my server but switching it to ssl:// worked for me, reasoning detailed here:

$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

这篇关于贝宝沙盒IPN-未得到验证响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆