dounao1875 2013-07-27 20:38
浏览 41
已采纳

PayPal IPN不是“已验证”或“无效”

I am trying to integrate PayPal IPN on a website. For some reason the IPN listener is neither verifying the payment or marking it invalid. I have placed mail() functions at different points in the code to notify me how much of the program is being run.

I have tried with and without using trim() on the $res variable. Both ways fail.

Here is my code:

    $req = 'cmd=_notify-validate';

    foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
    }
    mail('test@test.net', 0, 0); //EMAIL RECEIVED
    $header = "POST /cgi-bin/webscr HTTP/1.0
";
    $header .= "Content-Type: application/x-www-form-urlencoded
";
    $header .= "Content-Length: " . strlen($req) . "

";
    $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

    $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'];
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $address_street = $_POST['address_street'];
    $address_city = $_POST['address_city'];
    $address_zip = $_POST['address_zip'];
    $address_state = $_POST['address_state'];
    $address_country = $_POST['address_country'];
    $contact_phone = $_POST['contact_phone'];
    $payer_id = $_POST['payer_id'];


    if (!$fp) {
        //HTTP Error
        mail('test@test.net', 1, 1);
    } else {
        fputs ($fp, $header . $req);
        mail('test@test.net', 2, 2); //EMAIL RECEIVED
        while (!feof($fp)) {
            $res = fgets ($fp, 1024);
            if (strcmp (trim($res), "VERIFIED") == 0) {
                mail('test@test.net', 3, 3);
            } else if (strcmp (trim($res), "INVALID") == 0) {
                mail('test@test.net', 4, 4);
            } else {
                mail('test@test.net', 5, 5); //EMAIL RECEIVED
            }
        }
        fclose ($fp);
    }
}

The emails I am getting are 0, 2, and 5.

  • 写回答

1条回答 默认 最新

  • doumeng3080 2013-07-30 16:59
    关注

    Just answered another like yours. Paypal have stopped supporting HTTP1.0. Your header should now read:

    $header = "POST /cgi-bin/webscr HTTP/1.1
    ";
    $header .= "Content-Type: application/x-www-form-urlencoded
    ";
    $header .= "Host:www.sandbox.paypal.com
    ";
    $header .= "Connection:close
    ";
    $header .= "Content-Length: " . strlen($req) . "
    
    ";
    

    If live, just change the host domain name.

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧