PayPal IPN不会做任何事情

时间:2013-05-02 00:17:36

标签: php paypal paypal-ipn

我一直试图弄清楚过去12小时为何这不起作用。我找到了每个人现在应该使用IPN系统的最新和更新的代码。如果你不确定为什么POST标题现在是 HTTP / 1.1 而不是 HTTP / 1.0 ,请看这里: https://www.x.com/content/bulletin-ipn-and-pdt-scripts-and-http-1-1

在此脚本的任何块中,都应在log.txt中放置一条消息,但这种情况甚至不会发生。

任何人都能提供的任何见解都会很棒:

<?php 

  //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 (replaces old headers)
  $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 .="Connection: close\r\n";

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

  //error connecting to paypal
  if (!$fp) {
    file_put_contents('log.txt', 'httperror');
  }

  //successful connection    
  if ($fp) {
    fputs ($fp, $header . $req);

    while (!feof($fp)) {
      $res = fgets ($fp, 1024);
      $res = trim($res); //NEW & IMPORTANT

      if (strcmp($res, "VERIFIED") == 0) {
        if ($_POST["payment_status"] == "Completed") {
          $link = mysqli_connect("localhost", "removedforsecurity", "removedforsecurity", "removedforsecurity");
          if (!$link) {
            printf("Can't connect to localhost. Error: %s\n", mysqli_connect_error());
            exit();
          }

          $username = $_POST["custom"];
          $date = date('Y-m-d');

          /* update rows */
          mysqli_query($link, "UPDATE users SET access='user' WHERE username='myusername'");

          file_put_contents('log.txt', 'veri');
          /* close connection */
          mysqli_close($link);
        }
      }

      if (strcmp ($res, "INVALID") == 0) {
        file_put_contents('log.txt', 'failed');
      }
    }
    fclose($fp);
  }

?>

1 个答案:

答案 0 :(得分:0)

看看这些IPN Troubleshooting Steps。这可能有所帮助。还要检查您的PayPal帐户中的IPN历史记录,以确保IPN实际上已发送出去。它还应显示它是否已成功发送,或者是否失败并正在重试。在IPN历史消息的详细信息中,还应该有一个服务器正在撤销的状态代码。 PayPal期待200k响应。

相关问题