PayPal IPN不做任何事


PayPal IPN Won't Do Anything

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

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