【问题标题】:Paypal IPN will just not work properlyPaypal IPN 将无法正常工作
【发布时间】:2013-11-14 10:40:48
【问题描述】:

这是我的代码:

// post back to PayPal system to validate
$header .= "POST cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .="Host: www.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $header .="Connection: close\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, 2048); }

        if (strpos ($res), "VERIFIED") !== false) {
            switch ($transaction_type) {
                case "subscr_payment": 
                    if ($payment_status == "Completed" &&strtolower($receiver_email) == strtolower($receiverEmail)&&$currency=$payment_currency)

之前我曾尝试在这一行输入trim 语句:

if (strpos ($res, "VERIFIED") !== false)

我改成:

if (strcmp (trim($res), 'VERIFIED') == 0)

【问题讨论】:

  • 太棒了!谢谢!!!

标签: paypal postback paypal-ipn cgi-bin


【解决方案1】:

您的 'Connection: close' 标头(以 \r\n 结尾)正确地后跟一个空行(即另一个 \r\n),这是最后一个标头,但前一个标头('Content-Length' )。因此,“Connection: close”标头被视为有效负载的一部分。从前一个标题中删除空白行,即将倒数第二个\r\n\r\n 更改为\r\n。事实上,我会同时更改它们,并在最后一个标题之后添加另一个打印 \r\n,这样你就不会再像这样破坏它了。

【讨论】:

  • 版主说明 由于离题而产生的噪音多于信号,因此已删除此帖子下的评论。请保持 cmets 简短、主题和最专业的内容。
猜你喜欢
  • 1970-01-01
  • 2014-05-30
  • 2015-06-28
  • 2016-07-17
  • 1970-01-01
  • 2015-02-18
  • 2016-08-22
  • 1970-01-01
  • 2013-07-04
相关资源
最近更新 更多