几天前突然停止接收来自paypal的IPN消息。 我写了下面的代码
$url_parsed=parse_url('https://www.sandbox.paypal.com/cgi-bin/webscr');
$post_string = '';
foreach ($_POST as $field=>$value) {
$post_string .= $field.'='.urlencode(stripslashes($value)).'&';
}
$post_string.="cmd=_notify-validate";
$fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30);
$myFile = "testpaypal.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $post_string;
fwrite($fh, $stringData);
fwrite($fh, "------------");
if(!$fp){
return false;
} else {
fputs($fp, "POST $url_parsed[path] HTTP/1.0\r\n");
fputs($fp, "Host: $url_parsed[host]\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $post_string . "\r\n\r\n");
while(!feof($fp))
{
$ipn_response .= fgets($fp, 1024);
}
fclose($fp);
if (eregi("VERIFIED",$ipn_response)) {
fwrite($fh, "VERIFIED");
return true;
} else {
fwrite($fh, "UNVERIFIED");
return false;
}
}
fclose($fh);
此代码将err_num返回到“ 0 ”以及在“fclose($ fp);”之后打印$ ipn_response时行打印“ HTTP / 1.0 302找到位置:https://www.sandbox.paypal.com服务器:BigIP连接:关闭内容长度:0 ”
但无法在$ ipn_respnse中获得“验证”。
我尝试了所有可能的方法,例如使用“ssl://sandbox.paypal.com”更改解析网址 以及网上建议的所有其他解决方案。
自从过去三天以来,我一直陷入这个问题。所以,请帮帮我。提前感谢。
答案 0 :(得分:5)
您应该通过SSL连接。尝试更改此内容:
$fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30);
对此:
$fp = fsockopen("tls://" . $url_parsed['host'],"443",$err_num,$err_str,30);
答案 1 :(得分:0)
我也曾经遇到过这个问题。它完全让我疯了!问题是Hetzner(托管位置)因某种原因阻止了PayPal IP。在这种情况下,当您查看PayPal帐户中的IPN网络时,您会看到IPN已从某个日期停止发送通知。
答案 2 :(得分:0)
尝试将parse_url(https://www.paypal.com/cgi-bin/webscr)更改为沙箱网址(https://sandbox.paypal.com/cgi-bin/webscr)。
接下来,使用phpinfo()函数检查您的服务器是否已启用openssl以接收来自HTTPS的响应。
答案 3 :(得分:0)
来自PayPal的消息:
为了提高我们网站的性能,可扩展性和可用性,我们是 将扩大www.paypal.com的IP地址数量。我们 在2011年10月18日的公告中宣布了这一点。作为其中的一部分 扩展,我们将停止支持HTTP 1.0协议 2013年2月1日......
据说可以在http://www.paypal.com/pdt和http://www.paypal.com/ipn
找到更多信息我在你的代码中注意到了:
fputs($fp, "POST $url_parsed[path] HTTP/1.0\r\n");
您仍在使用HTTP 1.0
我不知道这是否会解决您的问题,但希望如果您仍然遇到问题会有所帮助。