【问题标题】:Paypal IPN callback stopped working in sandbox environmentPaypal IPN 回调在沙盒环境中停止工作
【发布时间】:2013-08-14 22:48:46
【问题描述】:

我在使用 paypal IPN 回调时遇到问题。 Paypal 的 IPN 回调在沙盒环境中停止工作。

在过去的几周里,我一直在测试我客户的网站,它一直运行正常 - 付款已完成,回调 IPN 已发送回网站,确认付款并更新网站的数据库.

我没有更改我的代码中的任何内容,它突然停止工作。付款仍然进行并保存在 paypal 帐户中,但 IPN 总是在重试...它没有完成。

这是使用的代码:

<?php

// STEP 1: read POST data

// Reading POSTed data directly from $_POST causes serialization issues with array data in the POST.
// Instead, read raw POST data from the input stream. 
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) { 
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
$value = urlencode(stripslashes($value)); 
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}

// STEP 2: POST IPN data back to PayPal to validate

$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

// In wamp-like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from [link removed] and set 
// the directory path of the certificate as shown below:
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if( !($res = curl_exec($ch)) ) {
// error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);

……

?>

将一些输出输出到文本文件,我发现它通过了第一步并在第二步停止,然后

if( !($res = curl_exec($ch)) ) {

我已经向 PayPal 提交了三个帮助请求,但仍未得到他们的答复。

【问题讨论】:

  • 丹麦人您好,感谢您的回复。我已经测试过该脚本。这是我尝试过的第一个。然后我更改为以下脚本:developer.paypal.com/webapps/developer/docs/classic/ipn/ht_ipn 该脚本运行良好,但突然停止运行。谢谢
  • 我一直在测试,似乎问题与 Curl 有关。 IPN 应该以这种方式工作: 1 - 贝宝使用交易变量发送回调 2 - 从接收文件将这些变量再次发送到贝宝,以进行确认 3 - 贝宝验证收到的信息 4 - 贝宝响应“已验证”或“无效”在我的回调文件中,接收到的变量被解析并正确发送回贝宝。如果我复制 url 并直接在浏览器中提交,我会得到“VERIFIED”响应。但是当通过 Curl 提交时,它给出了一个错误(无法连接到主机)。有任何想法吗?谢谢
  • 午饭后,神奇地它又开始在沙箱中工作了……但是当我将它传递给 Live 时,它​​又停止了工作。 IPN 没有到达我的回调文件(我推测)并给出了 HTTP 错误(406)。任何线索?除了 Curl 中的链接,我还需要配置什么吗?谢谢

标签: paypal callback sandbox paypal-ipn


【解决方案1】:

cURL 请求向 PayPal 发起 HTTP POST 以验证 IPN 消息。如果它在这一步停止,这意味着您确实收到了来自 PayPal 的 IPN POST,但在连接回 PayPal 时遇到了问题。

// error_log("Got " . curl_error($ch) . " when processing IPN data"); 包含什么?

为了解决这个问题,请测试从您的服务器到以下地址的 HTTPS 连接:

例如,您可以直接从您的服务器运行 cURL(假设您有 SSH 访问权限);

curl -v https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-validate

这应该返回类似于以下内容:

$ curl -v https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-validate
* About to connect() to www.sandbox.paypal.com port 443 (#0)
*   Trying 173.0.82.77...
* connected
* Connected to www.sandbox.paypal.com (173.0.82.77) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: /usr/ssl/certs/ca-bundle.crt
  CApath: none
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES256-SHA
* Server certificate:
*        subject: 1.3.6.1.4.1.311.60.2.1.3=US; 1.3.6.1.4.1.311.60.2.1.2=Delaware; businessCategory=Private Organization; serialNumber=3014267; C=US; postalCode=95131-2021; ST=California; L=San Jose; street=2211 N 1st St; O=PayPal, Inc.; OU=PayPal Production; CN=www.sandbox.paypal.com
*        start date: 2011-09-01 00:00:00 GMT
*        expire date: 2013-09-30 23:59:59 GMT
*        common name: www.sandbox.paypal.com (matched)
*        issuer: C=US; O=VeriSign, Inc.; OU=VeriSign Trust Network; OU=Terms of use at https://www.verisign.com/rpa (c)06; CN=VeriSign Class 3 Extended Validation SSL CA
*        SSL certificate verify ok.
> GET /cgi-bin/webscr?cmd=_notify-validate HTTP/1.1
> User-Agent: curl/7.28.1
> Host: www.sandbox.paypal.com
> Accept: */*
>
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 200 OK
< Date: Wed, 14 Aug 2013 20:15:53 GMT
< Server: Apache
< X-Frame-Options: SAMEORIGIN
< Set-Cookie: xxxxx    
< X-Cnection: close
< Set-Cookie: xxxx domain=.paypal.com; path=/; Secure; HttpOnly
< Set-Cookie: Apache=10.72.128.11.1376511353229960; path=/; expires=Fri, 07-Aug-43 20:15:53 GMT
< Vary: Accept-Encoding
< Strict-Transport-Security: max-age=14400
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
<
* Connection #0 to host www.sandbox.paypal.com left intact
**INVALID* Closing connection #0**
* SSLv3, TLS alert, Client hello (1):

如果您收到超时或 SSL 握手错误,则需要单独调查。

【讨论】:

  • 您好罗伯特,感谢您的回答。它又开始工作了。我昨天(现场)支付的款项待定,但今天已经确认。我又测试了 2 个,它们自动确认(IPN)。这些奇怪的事情有什么解释吗: - 7 月 26 日 - IPN 停止工作 - 沙盒。 - 8 月 14 日 - IPN 再次运行 - 沙盒。 - 8 月 14 日 - IPN 停止工作 - 实时模式(406 错误)。 - 8 月 15 日 - IPN 再次运行 - 实时模式。我没有任何改变。以下是提交给paypal的所有门票:#130810-000033,#130804-000067,#130731-000377,#130726-000079。谢谢
  • 就我而言,不,我所看到的任何东西都无法解释这一点。您可能已经有好几天无法连接到 IPN 验证端点,但我无法确定为什么会出现这种情况(我们不会将 IP 地址列入黑名单)。
  • 感谢罗伯特。我想我永远不会知道,但重要的是现在可以正常工作了:) 再次感谢您的帮助。
猜你喜欢
  • 2021-07-31
  • 2012-06-25
  • 2010-12-01
  • 2013-07-04
  • 2016-10-02
  • 1970-01-01
  • 2011-11-01
  • 2015-11-25
  • 2013-05-09
相关资源
最近更新 更多