【问题标题】:Php PayPal IPN returns INVALIDPhp PayPal IPN 返回无效
【发布时间】:2018-10-29 02:51:29
【问题描述】:

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

我怀疑我指向的 PayPal 地址不正确:

$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 的成功握手中完成,但返回 INVALID 作为 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 模拟器进行测试。

SO 推荐的解决方案都没有奏效。

请帮忙!

【问题讨论】:

  • PayPal 报告其沙盒环境和新的“ipnpb”地址存在问题。

标签: php https paypal-ipn


【解决方案1】:

作为记录,这个网址似乎工作正常:https://www.paypal.com/cgi-bin/webscr

【讨论】:

    猜你喜欢
    • 2011-10-26
    • 2016-11-28
    • 2012-04-26
    • 2010-12-01
    • 2014-10-21
    • 2013-01-20
    • 2016-10-21
    • 2016-01-24
    相关资源
    最近更新 更多