代码之家  ›  专栏  ›  技术社区  ›  Parapluie

Php PayPal IPN返回无效

  •  0
  • Parapluie  · 技术社区  · 6 年前

    我知道,截至2018年5月15日,PayPal IPN系统发生了一些变化。我碰巧正在实现我的第一个IPN侦听器;和 我不确定是因为我的资源(包括SO帖子,一些可以追溯到2009年的关于这个主题的帖子)被贝宝的变化淘汰了,还是仅仅因为我在这个领域缺乏经验。

    我怀疑我指的是错误的贝宝地址:

    $fh = fsockopen('ssl://www.paypal.com',443,$errno,$errstr,30);
    //$fh = fsockopen('https://www.sandbox.paypal.com',80,$errno,$errstr,30);
    //$fh = fsockopen('https://ipnpb.sandbox.paypal.com/cgi-bin/webscr',80,$errno,$errstr,30);
    

    第一个地址在与PayPal的成功握手中完成,但作为IPN响应返回无效。第二次握手,但不要超过 if (!$fh) 测验

    我尝试了下面的代码和Chris Muench在这里的答案中找到的CURL代码: PayPal IPN returns invalid in sandbox

    <?php
    // Paypal IPN code
    
    header('HTTP/1.1 200 OK'); // send header
    
    $resp = 'cmd=_notify-validate';
    foreach ($_POST as $parm => $var){
        $var = urlencode(stripslashes($var));
        $resp .= "&$parm=$var";
    }
    
    $httphead = "POST /cgi-bin/webscr HTTP/1.1\r\n";
    $httphead .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $httphead .= "Content-Length: " . strlen($resp) . "\r\n\r\n";
    
    // 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);
    //$fh = fsockopen('https://www.sandbox.paypal.com',443,$errno,$errstr,30);
    //$fh = fsockopen('https://ipnpb.sandbox.paypal.com/cgi-bin/webscr',443,$errno,$errstr,30);
    
    if (!$fh) {
        // if-fh does not work - cnxn FAILED
    } 
    else{
        // Connection opened, so spit back the response and get PayPal's view whether it was an authentic notification
        fputs ($fh,$httphead.$resp);
        while (!feof($fh)){
            $readresp = fgets ($fh, 1024);
            if (strcmp(trim($readresp),"VERIFIED") == 0){
                // if-fh works - cnxn OPEN';
                // WE ALL WIN!!
            }
            else if(strcmp(trim($readresp),"INVALID") == 0){
                // A possible hacking attempt, or
                // In my case, a possible hacking false-positive
            }
        }
    fclose ($fh);
    }
    ?>
    

    我正在沙盒帐户中使用IPN模拟器进行测试。

    这些建议的解决方案都没有奏效。

    请帮忙!

    1 回复  |  直到 6 年前
        1
  •  0
  •   Parapluie    6 年前

    作为记录,此url似乎运行良好: https://www.paypal.com/cgi-bin/webscr