2016-01-23 106 views
-1

我的ipn监听器今天停止工作(1/22/16)。我已经阅读了文章和贝宝文档,我的代码完全按照他们的文档进行,据我所知。我现在正在沙盒中测试。问题是我得到一个http连接错误,并停止了一切。该生产线是:paypal IPN监听器停止工作

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 
+0

你的代码应该记录的不仅仅是'http error'。当然有错误代码可用? – EJP

+0

感谢您的回复。不知道如何得到那个错误代码,但是在几个小时将我的头靠在墙上并使用本页面的cURL方法后,我放弃了这种方法:https://github.com/paypal/ipn-code-samples/斑点/主/ paypal_ipn.php。第一次工作。 Newby到stackoverload - 有什么我应该做的关闭这个线程? – msher220

+0

直到你解决你的问题是无法回答的。当提供的唯一信息是您自己设计的错误信息时,原则上让其他人知道发生了什么。 – EJP

回答

0

对此的更新。

我放弃了努力使上述方法工作,并从该网页使用卷曲的方法:github.com/paypal/ipn-code-samples/blob/master/paypal_ipn.php 曾为第一次投入后,我细节。

0

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

这些是来自PayPal包含的沙盒更改的详细信息,哪些是你作为一个开发人员可能需要做的评论:

沙盒已经更新到最新的TLS协议。您需要进行这些更改才能与Sandbox正确集成。这里是贝宝已经把帮助更新的微型网站: 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

我结束了硬编码的安全配置文件,我的使用贝宝IPN侦听器页面(我在ASP.NET开发)是这样的:

“设置的安全协议,以使用

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 

现在我的IPN监听器在重新工作贝宝沙箱。