use*_*999 3 php paypal paypal-ipn
几天前突然停止接收来自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);
Run Code Online (Sandbox Code Playgroud)
此代码将err_num返回到" 0 "以及在"fclose($ fp);"之后打印$ ipn_response时 行打印" HTTP/1.0 302找到位置:https://www.sandbox.paypal.com服务器:BigIP连接:关闭Content-Length:0 "
但无法在$ ipn_respnse中获得"验证".
我已经尝试了所有可能的方法,例如使用"ssl://sandbox.paypal.com"更改解析网址以及在网络上建议的所有其他解决方案.
自从过去三天以来,我一直陷入这个问题.所以,请帮帮我.
提前致谢.
您应该通过SSL连接.尝试改变这个:
$fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30);
Run Code Online (Sandbox Code Playgroud)
对此:
$fp = fsockopen("tls://" . $url_parsed['host'],"443",$err_num,$err_str,30);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2242 次 |
| 最近记录: |