问题描述
我只是在这里测试Paypal IPN。我已经设置了沙箱。我发送它假的IPN请求,它正在接收IPN。然后,我得到它返回的信息进行验证,我正在写一个文本文件的响应,所以我可以自己检查。
只有一个问题...响应为空白。
响应应该被接收为VERIFIED或INVALID,这些是唯一的2个可能的响应...所以发生了什么= S。非常感谢任何帮助。
整个代码如下:
$ ipn_post_data = $ _POST;
$ response =;
//选择url
$ url ='https://www.sandbox.paypal.com/cgi-bin/webscr';
//设置对PayPal的请求
$ request = curl_init();
curl_setopt_array($ request,array
(
CURLOPT_URL => $ url,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => http_build_query(array '=>'_notify-validate')+ $ ipn_post_data),
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => FALSE,
CURLOPT_SSL_VERIFYPEER => TRUE,
CURLOPT_CAINFO =>'cacert.pem',
));
//执行请求并获取响应和状态代码
$ response = curl_exec($ request);
$ status = curl_getinfo($ request,CURLINFO_HTTP_CODE);
//关闭连接
curl_close($ request);
$ fh = fopen(ipntest.txt,'a +');
$ date = date(Y-M-j H:i);
fwrite($ fh,$ date。Response:。$ response。\\\
);
fclose($ fh);
if($ status == 200& $ response =='VERIFIED')
{
//好!继续...
}
else
{
//不好。忽略或记录调查...
}
文本文件输出:
2012-Nov-26 23:24回复:
2012-Nov-26 23:25回复:
我以前一直使用这个代码,我一直在努力让它工作一个星期,所以它不只是暂时失败或某事......
我不确定CA文件究竟是什么,但我知道它与Paypal的SSL证书和建立SSL连接有关。当我开始查看cURL的错误时,我看到了以下内容:
[27-Nov-2012 21:46:11 UTC] cURL错误:[77]错误设置证书验证位置:
CAfile:/etc/ssl/certs/api_cert_chain.crt
CApath:/ etc / ssl / certs
我发现的快速解决方案是下载类。 (这是由推荐的,它使得处理IPN方式更容易,它为我没有CAFile提供了一个解决方案。如果您下载整个IpnListener.php包,它包括一个名为 cert 的文件夹,其中包含您需要的api_cert_chain.crt,并已配置使用。
I'm just testing the Paypal IPN here. I've got it set up with Sandbox. I'm sending it fake IPN requests, and it's receiving the IPN. Then, I'm getting it to return the information for verification, and I'm writing the response to a text file so I can check it out on my own. The IPN is firing fine, and the response is getting written to the text file.
There's just one problem... The response is blank.
The response is supposed to be received as "VERIFIED" or "INVALID", and these are the only 2 possible responses... so what's going on =S. Any help is greatly appreciated.
The entire code is posted below:
$ipn_post_data = $_POST;
$response = "";
// Choose url
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
// Set up request to PayPal
$request = curl_init();
curl_setopt_array($request, array
(
CURLOPT_URL => $url,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => http_build_query(array('cmd' => '_notify-validate') + $ipn_post_data),
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => FALSE,
CURLOPT_SSL_VERIFYPEER => TRUE,
CURLOPT_CAINFO => 'cacert.pem',
));
// Execute request and get response and status code
$response = curl_exec($request);
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
// Close connection
curl_close($request);
$fh = fopen( "ipntest.txt", 'a+' );
$date = date( "Y-M-j H:i" );
fwrite( $fh, $date . " Response: " . $response . "\n" );
fclose( $fh );
if($status == 200 && $response == 'VERIFIED')
{
// All good! Proceed...
}
else
{
// Not good. Ignore, or log for investigation...
}
Text file output:
2012-Nov-26 23:24 Response:
2012-Nov-26 23:25 Response:
I had been using this code previously, I've been trying to get it to work for a week, so it's not just a temporary failure or something...
Cheers guys.
So just for future reference, for people with this same problem:
The issue here was not having a CA file.
I'm unsure what exactly a CA file does but I know it has something to do with Paypal's SSL certificate and establishing an SSL connection. When I started looking at cURL's errors, I saw the following:
[27-Nov-2012 21:46:11 UTC] cURL error: [77] error setting certificate verify locations:
CAfile: /etc/ssl/certs/api_cert_chain.crt
CApath: /etc/ssl/certs
The quick solution that I found was to download the IpnListener.php class. (This was recommended by eldblz. It made dealing with IPN way easier AND it provided a solution to my not having a CAFile. If you download the entire IpnListener.php package, it includes a folder called cert which includes the api_cert_chain.crt that you need, and already has it configured for use.
这篇关于Paypal IPN获取空白确认(应为“VERIFIED”或“INVALID”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!