0

我有这个代码,一切正常。只是PayPal不断重新发送多个IPN。我已经阅读了 PayPal 的论坛,他们说 PayPal 没有从我这里获得 HTTP/1.1 200 OK,所以它一直在重新发送 IPN。我该怎么办?

function sql_execute($sql){
    $sql_connect = @mysql_connect($_SERVER['HTTP_HOST'].':3306','root', '****') or
       die('Could not connect: ' . mysql_error());
    mysql_select_db('4bkk');
    mysql_query($sql);
    $rows = mysql_affected_rows($sql_connect);  //mysql_insert_id();
    mysql_close();
    return $rows;
}

function sql_query($sql){
    // echo $sql;
    $sql_connect = @mysql_connect($_SERVER['HTTP_HOST'].':3306','****', 'zzz111') or
        die('Could not connect: ' . mysql_error());
    mysql_select_db('4bkk');
    $rs = mysql_query($sql) or die(mysql_error());
    mysql_close();
    return $rs;
}

function logtrace($o){
    $q = "INSERT INTO log (trace, trace_time) VALUES ('$o', NOW() )";
    sql_query($q);
}

function send_email($t,$s,$m,$h){
    //mail($t, $s, $m, $h);

    $fh = fopen('result_ipn_test.txt', 'w');
    fwrite($fh, $t.' '.$s.' '.$m.' '.$h);
    fclose($fh);

    logtrace('Mail is sent and exit called');

    exit();
}

logtrace('__________NEW SESSION__________');

$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';

$postFields = 'cmd=_notify-validate';

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

$ch = curl_init();

curl_setopt_array($ch, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $postFields
));

$result = curl_exec($ch);
$info = curl_getinfo($ch);

logtrace($info['url']);

curl_close($ch);

//get buyers information from PAYPAL checkout
$email = $_POST['payer_email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$amount = $_POST['amount3'];
$plan = $_POST['option_selection1'];

logtrace($email.' -- '.$active);

$q = "SELECT * FROM users WHERE email='$email' AND user_level='' AND active='unverified'"; //Unprocessed record = no user_level and active = 'unverified'

$ex = sql_execute($q);
//logtrace("THIS ".$q."  =>  ".$ex);

if(sql_execute($q)){
    logtrace('IT IS TRUE');
    $flag = TRUE;
}
else{
    logtrace('FALSE');
    $flag = FALSE;
}

logtrace($result.' RESPONSE FROM PAYPAL');
if(($result=='VERIFIED') && $flag){ //Checks first if PayPal is valid, email address exists in
                                    //records and checks if user_level='' and active='unverified',
                                    //if not enters.
    logtrace('USER IS READY FOR VERIFICATION');

    $q = "SELECT * FROM users WHERE email='$email'";
    $data = sql_query($q);

    $con = mysql_fetch_array($data);

    //Get buyers information from the database
    $email2 = $con['email'];
    $first_name = $con['first_name'];
    $last_name = $con['last_name'];
    $active = $con['active'];
    $user_level = $con['user_level'];

    logtrace('Emails match');

    $u = "UPDATE users SET active='verified', user_level='$plan' WHERE email='$email' LIMIT 1";

    if (sql_query($u)) { //Successful verification
        logtrace('|| Update was sucessful');
    }
    else{ // Unsuccessful verification.
        logtrace('|| Something went wrong with update.');
    }
}
else{ // The user doesn't have any record in the database.
    $q = "SELECT * FROM users WHERE email='$email' AND (user_level='Monthly' OR user_level='Quarterly' OR user_level='Yearly')";

    if(sql_execute($q)){ // The user is already verified
        logtrace('THE USER IS ALREADY VERIFIED');
    }
    else{ // The user does not exist.
        logtrace('THE USER HAS NO RECORD ON DATABASE');

    }
}
4

1 回答 1

1

请参考示例代码https://www.x.com/instant-payment-notification-4

根据上面的代码,您可以尝试设置 curl 选项

CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1 CURLOPT_HTTPHEADER,数组('连接:关闭')

在您设置为 curl_setopt_array 的上述代码中...

我认为这应该可以解决您的 HTTP/1.1 200 OK 问题。

于 2012-11-02T06:10:01.417 回答