PayPal IPN已停止工作

时间:2014-02-06 20:42:53

标签: php curl paypal 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 "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
}
?>

2 个答案:

答案 0 :(得分:1)

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

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

如果它显示它正在发送但是获得200响应以外的其他内容意味着您的IPN脚本失败。您可以检查Web服务器日志,以获取有关错误确切内容的详细信息并将其解决。

答案 1 :(得分:0)

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

似乎发送无关数据

我正在记录paypal对验证的响应,它会在我记录的重要位上发送一些内容


Content-Type:text / html;字符集= UTF-8  -空行-  8  VERIFIED  0