首页 > 解决方案 > PayPal IPN 突然停止工作

问题描述

大约 6 小时前它工作正常。现在一切突然停止工作。我检查了 IPN 历史页面。在 IPN 历史上,它被发送和接收 200 响应。一切都应该正常工作。

我还添加了额外的代码:

    foreach($_REQUEST as $key=>$value){
        $reqa .= "&$key=$value"; 
    }
        $fh = fopen('log/invalid-lol.txt','w');
        fwrite($fh,$reqa);
        fclose($fh);

即使我重新加载 IPN 页面,它也可以帮助我创建文件。我也尝试过 IPN 模拟器,握手得到验证。忘记IPN数据,它甚至没有创建即使我重新加载页面也应该创建的日志文件。任何事情都没有错误。

这是完整的代码:

<?php

    // STEP 1: Read POST data

    // reading posted data from directly from $_POST causes serialization 
    // issues with array data in POST
    // reading raw POST data from input stream instead.
    foreach($_REQUEST as $key=>$value){
        $reqa .= "&$key=$value"; 
    }
    $fh = fopen('log/invalid-lol.txt','w');
    fwrite($fh,$reqa);
    fclose($fh);

    $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 post from PayPal system and add 'cmd'
    $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://ipnpb.sandbox.paypal.com/cgi-bin/webscr'); // change to [...]sandbox.paypal[...] when using sandbox to test
    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);


    // STEP 3: Inspect IPN validation result and act accordingly

    if (strcmp ($res, "VERIFIED") == 0) {
        // 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 payment

        // assign posted variables to local variables

        $item_name = $_POST['item_name'];
        $item_no = $_POST['item_number'];
        $payment_status = $_POST['payment_status'];
        if ($_POST['mc_gross'] != NULL)
            $payment_amount = $_POST['mc_gross'];
        else
            $payment_amount = $_POST['mc_gross1'];
        $payment_currency = $_POST['mc_currency'];
        $txn_id = $_POST['txn_id'];
        $txn_type = $_POST['txn_type'];
        $case_type = $_POST['case_type'];
        $receiver_email = urldecode($_POST['receiver_email']);
        $payer_email = urldecode($_POST['payer_email']);


        foreach($_POST as $key=>$value){
         $req .= "&$key=$value"; 
        }

        $rand = rand(0,99);
        $fh = fopen('log/valid-'.$rand.'-'.$item_no.'.txt','w');
        fwrite($fh,$req);
        fclose($fh);

    } else if (strcmp ($res, "INVALID") == 0) {

        $rand = rand(1000,99999);

        $fh = fopen('log/invalid-'.$rand.'.txt','w');
        fwrite($fh,$req);
        fclose($fh);

    }

?>

标签: phppaypalpaypal-ipn

解决方案


推荐阅读