paypal IPN听众停止工作

时间:2016-01-23 00:28:11

标签: paypal paypal-ipn

我的ipn听众今天(16/22/16)停止了工作。据我所知,我已经阅读了文章和paypal文档,我的代码完全遵循他们的文档。我现在在沙盒中测试。问题是,我收到一个http连接错误,并停止一切。该行是:

<?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

================== 运行日志文件后如下所示:

{{1}}

3 个答案:

答案 0 :(得分:0)

对此进行更新。

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

答案 1 :(得分:0)

而不是:

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

尝试:

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

汤姆

答案 2 :(得分:0)

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

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

Sandbox已更新为最新的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沙箱中工作。

相关问题