【问题标题】:paypal IPN listener stopped working贝宝 IPN 监听器停止工作
【发布时间】:2016-04-29 17:33:12
【问题描述】:

我的 ipn 监听器今天(16 年 1 月 22 日)停止工作。据我所知,我已阅读文章和贝宝文档,我的代码完全遵循他们的文档。我现在正在沙箱中进行测试。问题是我收到一个 http 连接错误,这会停止一切。该行是:

if (!$fp) {
//can't go on
}

这是完整的代码

<?php

$log = fopen("ipn.log", "a");
fwrite($log, "\n\nipn - " . gmstrftime ("%b %d %Y %H:%M:%S", time()) . "\n");

header('HTTP/1.1 200 OK'); 

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

fwrite($log,"$req is: " . $req."\r\n");

$sandbox=1;

if($sandbox == 1) {
    $header = "POST https://www.sandbox.paypal.com/cgi-bin/webscr HTTP/1.1\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen("tls://www.sandbox.paypal.com", "443", $errno, $errstr, 30);
} else {

    $header = "POST https://www.paypal.com/cgi-bin/webscr HTTP/1.1\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ("ssl://www.paypal.com", "443", $errno, $errstr, 30);
}


fputs($fp, $header . $req);

fwrite($log,"error no= " . $errno . " errstr= " . $errstr . "\r\n");
// ABOVE RETURNS 0 FOR $errno and null for $errstr


if (!$fp) {
// HTTP ERROR HAPPENS HERE
fwrite($log, "http error\r\n");
} else {

    while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    $res = trim($res);

        if (strcmp ($res, "VERIFIED") == 0) {
        // do stuff here
        fwrite($log, "verified\r\n");
        }
        else if (strcmp ($res, "INVALID") == 0) {
        fwrite($log, "invalid\r\n");
        } 
    }
fclose ($fp);
}
fclose ($log);
?>

================== 运行后的日志文件是这样的:

ipn - Jan 23 2016 00:06:14
$req is: cmd=_notify-validate&payment_type=instant&payment_date=Fri+Jan+22+2016+15%3A30%3A44+GMT-0800+%28Pacific+Standard+Time%29&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer%40paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John+Smith&address_country=United+States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San+Jose&address_street=123+any+street&business=seller%40paypalsandbox.com&receiver_email=seller%40paypalsandbox.com&receiver_id=seller%40paypalsandbox.com&residence_country=US&item_name1=something&item_number1=AK-1234&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross1=12.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=378619000&notify_version=2.1&custom=2_2%2Bxc&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AIlWjbxX7iz7ACchkv5lDNHsBr8a
error no= 0 errstr= 
http error

【问题讨论】:

  • 您的代码应该记录的不仅仅是“http 错误”。确定有可用的错误代码吗?
  • 感谢您的回复。不知道如何获取该错误代码,但我在头撞墙数小时后放弃了这种方法,并使用了此页面中的 cURL 方法:github.com/paypal/ipn-code-samples/blob/master/paypal_ipn.php。第一次工作。新手到 stackoverload - 我应该做些什么来关闭这个线程?
  • 直到您解决您的问题无法回答。当提供的唯一信息是您自己设计的错误消息时,原则上其他人会知道发生了什么。
  • 不是完全无法回答,因为它是最新的帖子。

标签: paypal paypal-ipn


【解决方案1】:

我在同一天遇到了同样的问题。在使用 PayPal 进行研究后,我发现 PayPal 于 2016 年 1 月 20 日在沙盒中更改了他们的安全协议。您需要确保您的网络服务器使用 TLS 1.2 和 HTTP 1.1 协议。如果您的网站已托管但您不确定,请联系您的主机。

这些是来自 PayPal 的 cmets,其中包含沙盒更改的详细信息以及您作为开发人员可能需要做的事情:

沙盒已更新为最新的 TLS 协议。您需要进行这些更改才能与 Sandbox 正确集成。这是 PayPal 为帮助更新而建立的一个微型网站: https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ1913&expand=true&locale=en_US

这是 TLS 1.2 和 HTTP/1.1 升级的第一个链接:https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US

我最终硬编码了我的 PayPal IPN 侦听器页面使用的安全配置文件(我正在 ASP.NET 中开发),如下所示:

'设置要使用的安全协议

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

现在我的 IPN 监听器在 PayPal 沙箱中再次工作。

【讨论】:

    【解决方案2】:

    代替:

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

    尝试:

    "$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";"....

    汤姆

    【讨论】:

      【解决方案3】:

      对此进行更新。

      我放弃了尝试使上述方法起作用并使用此页面中的 cURL 方法:github.com/paypal/ipn-code-samples/blob/master/paypal_ipn.php 输入我的详细信息后第一次工作。

      【讨论】:

        猜你喜欢
        • 2015-05-27
        • 2019-03-31
        • 2013-09-02
        • 2013-06-12
        • 2019-01-09
        • 2016-01-09
        • 2012-02-22
        • 2013-06-14
        • 2013-01-04
        相关资源
        最近更新 更多