Paypal IPN 获得空白确认(应为“已验证"或“无效")

2023-06-23php开发问题
3

本文介绍了Paypal IPN 获得空白确认(应为“已验证"或“无效")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我只是在这里测试 Paypal IPN.我已经用 Sandbox 设置好了.我正在向它发送虚假的 IPN 请求,它正在接收 IPN.然后,我让它返回信息以进行验证,并将响应写入文本文件,以便我可以自己检查.IPN 运行良好,响应正在写入文本文件.

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.

响应应该被接收为已验证"或无效",而这些是仅有的 2 个可能的响应......所以发生了什么 =S.非常感谢任何帮助.

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.

完整代码如下:

$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 . "
" );
fclose( $fh );

if($status == 200 && $response == 'VERIFIED')
{
    // All good! Proceed...
}
else
{
    // Not good. Ignore, or log for investigation...
}

文本文件输出:

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...

伙计们干杯.

推荐答案

所以仅供将来参考,对于有同样问题的人:

So just for future reference, for people with this same problem:

这里的问题是没有 CA 文件.

我不确定 CA 文件究竟是做什么的,但我知道它与 Paypal 的 SSL 证书和建立 SSL 连接有关.当我开始查看 cURL 的错误时,我看到了以下内容:

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

我找到的快速解决方案是下载 IpnListener.php 类.(这是 eldblz 推荐的.它使处理 IPN 变得更容易,并且为我没有 CAFile 提供了解决方案.如果您下载整个 IpnListener.php 包,它包含一个名为 cert 的文件夹,其中包含您需要的 api_cert_chain.crt,并且已经对其进行了配置以供使用.

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 获得空白确认(应为“已验证"或“无效")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17