PayPal IPN返回无效 [英] PayPal IPN returning INVALID

查看:131
本文介绍了PayPal IPN返回无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用来解释PayPal通知的代码.我不断收到来自贝宝的无效"信息.很抱歉,这个问题本质上只是一个代码片段,但是我已经研究了很长时间了,而且似乎没有取得任何进展.

this is my code to interpret PayPal's notification. I keep receiving "INVALID" from paypal. I'm sorry that this question is essentially just a code snippet, but I've been working on it for so long and can't seem to make any progress.

如果任何人有任何想法,但需要查看一些调试信息,那么我设法通过php mail()函数来获取它的方法-所以问一下就可以了.

If anyone has any ideas, but needs to see some debug infomation, then the way I'm managing to get it is via the php mail() function - so just ask and I can get it.

<?php
    $debugmessage = "";

    require($_SERVER['DOCUMENT_ROOT'] . '/xxxx.php');
    mysql_connect("$server", "$user", "$password") or die(mysql_error());
    mysql_select_db("$database") or die(mysql_error());

    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';
    foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
    }

    // post back to PayPal system to validate
    $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

    if (!$fp) {
        // HTTP ERROR
        echo "http error";
    } else {
        fputs ($fp, $header . $req);
        while (!feof($fp)) {
            $res = fgets ($fp, 1024);
            $debugmessage .= "|".$res;
            $debugmessage .= "|".strlen($req);
            if (strcmp ($res, "VERIFIED") == 0) {
                // PAYMENT VALIDATED & VERIFIED!
                $debugmessage .= "|"+"payment VALID";

                $email = $_POST['payer_email'];
                $password = mt_rand(100000, 999999);
                mysql_query("INSERT INTO users (email, password) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error());
                $to      = $email;
                $subject = 'Download Area | Login Credentials';
                $message = '
                Thank you for your purchase!
                Your account information
                -------------------------
                Email: '.$email.'
                Password: '.$password.'
                -------------------------
                You can now login at xxxxxxxxxxxx';
                $headers = 'From:xxxxxxx@xxxxxxx.com' . "\r\n";
                mail($to, $subject, $message, $headers);
            }
            else if (strcmp ($res, "INVALID") == 0) {
                $debugmessage .= "|"."payment INvalid";
                // PAYMENT INVALID & INVESTIGATE MANUALY!
                $to      = 'xxxxxx@xxxxxxx.com';
                $subject = 'Download Area | Invalid Payment';
                $message = '
                Dear Administrator,
                A payment has been made but is flagged as INVALID.
                Please verify the payment manualy and contact the buyer.
                Buyer Email: '.$email.'
                ';
                $headers = 'From:xxxxxx@xxxxxxx.com' . "\r\n";
                mail($to, $subject, $message, $headers);

            }
        }
        fclose ($fp);
    }
    mail("xxxxxxx@gmail.com",$debugmessage,"");
?>

以防万一有人理解可怕的混乱,一旦脚本运行,$debugmessage就会包含该错误:

Just in case anyone understands that horrible mess, $debugmessage contains this once the script has run:

|HTTP/1.0 200 OK |840|X-Frame-Options: SAMEORIGIN |840|Strict-Transport-Security: max-age=14400 |840|Strict-Transport-Security: max-age=14400 |840|Content-Type: text/html; charset=UTF-8 |840|Date: Tue, 05 Mar 2013 04:42:09 GMT |840|Content-Length: 7 |840|Connection: close |840| |840|INVALID|840|payment INvalid

我已经读过关于不使用fsockopen以及也使用"CURL"的内容,但是我对这些东西不太自信.

I've read things about not using fsockopen and also using something called "CURL", but I'm not too confident with this stuff.

任何帮助将不胜感激.

推荐答案

5小时后...我的解决方案是删除代码并使用

5 hours later... my solution was to chuck the code and redo it using this tutorial.

强烈推荐.

这篇关于PayPal IPN返回无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆