-1

在过去的 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);
  }

?>
4

1 回答 1

0

看看这些IPN 故障排除步骤。这些可能会有所帮助。还要检查您 PayPal 帐户中的 IPN 历史记录,以确保 IPN 确实被发送出去。它还应该显示它是否发送成功,或者它是否失败并正在重试。在 IPN 历史消息的详细信息中,还应该有您的服务器正在返回的状态代码。PayPal 期望得到 200ok 响应。

于 2013-05-02T13:44:47.347 回答