PayPal IPN 已停止工作

Posted

技术标签:

【中文标题】PayPal IPN 已停止工作【英文标题】:PayPal IPN has stopped working 【发布时间】:2014-03-04 00:46:02 【问题描述】:

以下脚本运行了好几个小时,但突然停止运行。

我没有改变任何东西。

下面有什么看起来有问题的东西会阻止它正常工作吗?

<?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 "http://curl.haxx.se/docs/caextract.html" 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 (strcmp ($res, "VERIFIED") == 0) 
    // The IPN is verified, process it:
    // check whether the payment_status is Completed
    // check that txn_id has not been previously processed
    // check that receiver_email is your Primary PayPal email
    // check that payment_amount/payment_currency are correct
    // process the notification

    // assign posted variables to local variables
    $item_name = $_POST['item_name'];
    $item_number = $_POST['item_number'];
    $payment_status = $_POST['payment_status'];
    $payment_amount = $_POST['mc_gross'];
    $payment_currency = $_POST['mc_currency'];
    $txn_id = $_POST['txn_id'];
    $receiver_email = $_POST['receiver_email'];
    $payer_email = $_POST['payer_email'];


    // process payment
        // Added pp_trans_id which is the unique Transaction ID provided by PayPal
        // Added reg_date which is in UNIX_TIME()
        // Set WHERE to be equal to $id for perfect match
    mysql_connect('localhost', 'wgaxzhpl_registe', '****');
    mysql_select_db('wgaxzhpl_register');
    $id = $_POST['custom'];
   $insert      = mysql_query("INSERT INTO `log` (txn_id, active) VALUES ('".$txn_id."', 1);");


 else if (strcmp ($res, "INVALID") == 0) 
    // IPN invalid, log for manual investigation

?>

【问题讨论】:

您是否收到任何错误消息?你有网络或mysql访问权限吗? 没有错误,托管和 mysql 工作得很好! 【参考方案1】:

见http://forums.oscommerce.com/topic/395932-paypal-ipns-have-stopped-working-for-us-yesterday/

它似乎正在发送无关数据

我正在记录贝宝对验证的响应,它会围绕我记录的重要位发送一些内容


内容类型:文本/html;字符集=UTF-8 -空行- 8 已验证 0


【讨论】:

【参考方案2】:

检查您 PayPal 帐户中的 IPN 历史记录,以查看 IPN 是否真的被发送,以及返回的响应是什么。如果它显示它们正在被发送并包含 200 响应,那么这意味着您的脚本正在被命中并成功完成。在这种情况下,您需要检查脚本的逻辑,看看为什么它没有按照您的想法执行。

如果根本没有发送,则需要仔细检查 PayPal 帐户中的 IPN 配置或付款请求中使用的通知 URL。

如果它显示它正在发送但收到的响应不是 200 响应,则意味着您的 IPN 脚本失败。您可以检查您的网络服务器日志以了解确切的错误并解决它。

【讨论】:

我检查了我的 IPN 历史,一切都很好,我有 Http 200 响应和一条 IPN 消息 好的,正如我所提到的,这意味着脚本正在被 PayPal 的服务器访问,它返回的响应表明它已成功完成。如果您没有看到脚本运行时应该发生的情况,则需要仔细检查您的逻辑。

以上是关于PayPal IPN 已停止工作的主要内容,如果未能解决你的问题,请参考以下文章

Paypal Sandbox 突然停止发送 IPN

PayPal IPN 突然停止流入

Curl / php 来自 PayPal IPN url 的空响应

Paypal“SetExpressCheckout”API 方法已停止使用沙盒卖家账户

PayPal IPN 沙盒不工作,但模拟器可以

我的 PayPal 脚本突然停止验证 SSL 证书