贝宝IPN模拟器

时间:2018-06-25 20:31:06

标签: php paypal paypal-ipn

过去20个小时(2天),我一直在尝试设置IPN,每次我想运行测试时,它都不允许我说:“未发送IPN,并且握手没有经过验证。查看您的信息。“

1) 当我将“ openssl s_client -connect api-3t.sandbox.paypal.com:443 -showcerts -CApath / etc / ssl / certs /”放到服务器上时,通常显示没问题,所以这不是问题。

2) 在我的Paypal IPN设置中,我有https://www.(mydomain.com)/listener.php

我的listener.php(我尝试过的5个之一):

<?php
//
// STEP 1 - be polite and acknowledge PayPal's notification
//

header('HTTP/1.1 200 OK');

//
// STEP 2 - create the response we need to send back to PayPal for them to confirm that it's legit
//

$resp = 'cmd=_notify-validate';
foreach ($_POST as $parm => $var) 
    {
    $var = urlencode(stripslashes($var));
    $resp .= "&$parm=$var";
    }

// STEP 3 - Extract the data PayPal IPN has sent us, into 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'];
  $txn_id           = $_POST['txn_id'];
  $receiver_email   = $_POST['receiver_email'];
  $payer_email      = $_POST['payer_email'];
  $record_id        = $_POST['custom'];



// STEP 4 - Get the HTTP header into a variable and send back the data we received so that PayPal can confirm it's genuine

$httphead = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$httphead .= "Content-Type: application/x-www-form-urlencoded\r\n";
$httphead .= "Content-Length: " . strlen($resp) . "\r\n\r\n";

 // Now create a ="file handle" for writing to a URL to paypal.com on Port 443 (the IPN port)

$errno ='';
$errstr='';

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

// STEP 5 - Nearly done.  Now send the data back to PayPal so it can tell us if the IPN notification was genuine

 if (!$fh) {

// Uh oh. This means that we have not been able to get thru to the PayPal server.  It's an HTTP failure    

else    {
           fputs ($fh, $httphead . $resp);
           while (!feof($fh))
                {
                $readresp = fgets ($fh, 1024);
                if (strcmp ($readresp, "VERIFIED") == 0) 
                    {



//
                    }

                else if (strcmp ($readresp, "INVALID") == 0) 
                    {

//              Man alive!  A hacking attempt?

                    }
                }
fclose ($fh);
        }
//
//
// STEP 6 - Pour yourself a cold one.
//
//

?>

解决可能要花一些时间,甚至可能不需要2分钟,但是如果有人知道原因,我将非常高兴。 它还可以帮助其他人。

0 个答案:

没有答案