PHP PayPal IPN 返回无效



我知道截至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)测试。

我已经尝试了下面的代码,以及克里斯·穆恩奇在这里的答案中找到的 CURL 代码:PayPal IPN 在沙箱中返回无效

<?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.1rn";
$httphead .= "Content-Type: application/x-www-form-urlencodedrn";
$httphead .= "Content-Length: " . strlen($resp) . "rnrn";
// 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 推荐的解决方案均无效。

请帮忙!

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

最新更新