【发布时间】: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