簡體   English   中英

PHP-PayPal IPN 301永久移動

[英]PHP - PayPal IPN 301 moved permanently

我之前用過多次用PHP編寫的PayPal IPN腳本時遇到了麻煩,但現在卻遇到此錯誤。

[07/31/2018 4:42 PM] - FAIL: IPN Validation Failed.
IPN POST Vars from Paypal:

    IPN Response from Paypal Server:
     HTTP/1.1 301 Moved Permanently
    Server: AkamaiGHost
    Content-Length: 0
    Location: https://www.paypal.com/smarthelp/article/how-do-i-check-and-update-my-web-browser-faq3893
    Date: Tue, 31 Jul 2018 23:42:14 GMT
    Connection: close
    Set-Cookie: akavpau_ppsd=1533081134~id=4fddfa711d2216538f54014af27277b0; Domain=www.paypal.com; Path=/; Secure; HttpOnly
    Strict-Transport-Security: max-age=63072000

我正在使用Micah Carrick制作的腳本。 我的編輯看起來像這樣。 paypal.php

<?php
require('../inc/db.php');

define('LOG_FILE', 'ipn_results.log');
define('SSL_P_URL', 'https://www.paypal.com/cgi-bin/webscr');
define('SSL_SAND_URL','https://www.sandbox.paypal.com/cgi-bin/webscr');

class paypal_class {

   var $last_error;                 // holds the last error encountered

   var $ipn_log;                    // bool: log IPN results to text file?

   var $ipn_log_file;               // filename of the IPN log
   var $ipn_response;               // holds the IPN response from paypal   
   var $ipn_data = array();         // array contains the POST values for IPN

   var $fields = array();           // array holds the fields to submit to paypal

   function paypal_class() {

      // initialization constructor.  Called when a class is created.

      $this->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';

      $this->last_error = '';

      $this->ipn_log_file = '/ipn_results.log';
      $this->ipn_log = true; 
      $this->ipn_response = '';

      // populate $fields array with a few default values.  See the PayPal
      // documentation for a list of fields and their data types. These default
      // values can be overwritten by the calling script.

      $this->add_field('rm','2');           // Return method = POST
      $this->add_field('cmd','_xclick'); 

   }

   function add_field($field, $value) {


      $this->fields["$field"] = $value;
   }

   function submit_paypal_post() {


     echo "<html>\n";
     echo "<head><title>Processing Payment...</title>";
     echo "<body onLoad=\"document.forms['paypal_form'].submit();\">\n";
     echo "<center><h2>Please wait, your order is being processed and you";
     echo " will be redirected to the paypal website.</h2></center>\n";
     echo "<form method=\"post\" name=\"paypal_form\" ";
     echo "action=\"".$this->paypal_url."\">\n";

     foreach ($this->fields as $name => $value) 
     {
         echo "<input type=\"hidden\" name=\"$name\" value=\"$value\"/>\n";
      }
     echo "<center><br/><br/>If you are not automatically redirected to ";
     echo "paypal within 5 seconds...<br/><br/>\n";
     echo "<input type=\"submit\" value=\"Click Here\"></center>\n";
     echo "</body></html>\n";

   }

   function validate_ipn() {
    mysqli_query($db, "UPDATE matches SET status = 3");
      // parse the paypal URL
      $url_parsed=parse_url($this->paypal_url);        

      // read post data from PayPal and add 'cmd'
    $req = 'cmd=_notify-validate';
    if(function_exists('get_magic_quotes_gpc')) {
       $get_magic_quotes_exists = true;
    } 
    foreach ($myPost as $key => $value) {        
       if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
            $value = urlencode(stripslashes($value)); 
       } else {
            $value = urlencode($value);
       }
       $req .= "&$key=$value";
    }

      // open the connection to paypal
      $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); 
      if(!$fp) {

         // could not open the connection.  If loggin is on, the error message
         // will be in the log.
         $this->last_error = "fsockopen error no. $errnum: $errstr";
         $this->log_ipn_results(false);       
         mysqli_query($db, "UPDATE matches SET status = 5");
         return false;

      } else { 

         // Post the data back to paypal
         fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n"); 
         fputs($fp, "Host: $url_parsed[host]\r\n"); 
         fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); 
         fputs($fp, "Content-length: ".strlen($post_string)."\r\n"); 
         fputs($fp, "Connection: close\r\n\r\n"); 
         fputs($fp, $post_string . "\r\n\r\n"); 

         // loop through the response from the server and append to variable
         while(!feof($fp)) { 
            $this->ipn_response .= fgets($fp, 1024); 
         } 

         fclose($fp); // close connection
        mysqli_query($db, "UPDATE matches SET status = 8");
      }

      if (eregi("VERIFIED",$this->ipn_response)) {

         // Valid IPN transaction.
         $this->log_ipn_results(true);
         mysqli_query($db, "UPDATE matches SET status = 9");
         return true;       

      } else {

         // Invalid IPN transaction.  Check the log for details.
         $this->last_error = 'IPN Validation Failed.';
         $this->log_ipn_results(false);   
         mysqli_query($db, "UPDATE matches SET status = 6");
         return false;

      }

   }

   function log_ipn_results($success) {

      if (!$this->ipn_log) return;  // is logging turned off?

      // Timestamp
      $text = '['.date('m/d/Y g:i A').'] - '; 

      // Success or failure being logged?
      if ($success) $text .= "SUCCESS!\n";
      else $text .= 'FAIL: '.$this->last_error."\n";

      // Log the POST variables
      $text .= "IPN POST Vars from Paypal:\n";
      foreach ($this->ipn_data as $key=>$value) {
         $text .= "$key=$value, ";
      }

      // Log the response from the paypal server
      $text .= "\nIPN Response from Paypal Server:\n ".$this->ipn_response;

      // Write to log
      $fp=fopen($this->ipn_log_file,'a');
      fwrite($fp, $text . "\n\n"); 

      fclose($fp);  // close file
   }

   function dump_fields() {

      echo "<h3>paypal_class->dump_fields() Output:</h3>";
      echo "<table width=\"95%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">
            <tr>
               <td bgcolor=\"black\"><b><font color=\"white\">Field Name</font></b></td>
               <td bgcolor=\"black\"><b><font color=\"white\">Value</font></b></td>
            </tr>"; 

      ksort($this->fields);
      foreach ($this->fields as $key => $value) {
         echo "<tr><td>$key</td><td>".urldecode($value)."&nbsp;</td></tr>";
      }

      echo "</table><br>"; 
   }
}     

paypal.class.php

<?php

    include_once('../inc/db.php');
    require ('../inc/steamauth.php');

    function filter($var)
        {
            return stripslashes(htmlspecialchars($var));
        }

    require_once('paypal.class.php');  // include the class file
    $p = new paypal_class; 
    $p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';

    $this_script = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];


    if (empty($_GET['action'])) $_GET['action'] = 'process';  

    switch ($_GET['action']) {

       case 'process':

       $teamid = mysqli_real_escape_string($db, $_POST['teamid']);
       $type = mysqli_real_escape_string($db, $_POST['type']);

        switch($type) {

        case 'me':
            $cost = '0.01';
        break;

        case 'team':
            $cost = '0.01';
        break;

        }

          $p->add_field('business', 'MY EMAIL');
          $p->add_field('return', 'https://'.$_SERVER['HTTP_HOST']); //The success URL
          $p->add_field('custom', $teamid);
          $p->add_field('cancel_return', 'http://'.$_SERVER['HTTP_HOST']); // The "canceled" URL
          $p->add_field('notify_url', $this_script.'?action=ipn'); //The IPN URL, the URL pointing to THIS page.
          $p->add_field('item_number', filter($_POST['type']));
          $p->add_field('item_name', $_POST['type'] . '');
          $p->add_field('amount', $cost); // How ever much the VIP cost.

          $p->submit_paypal_post();

          break;

          case 'ipn':

          $db = mysqli_connect("localhost", "root", "*****", "***");

$problem =  mysqli_query($db, "UPDATE matches SET status = '1'");

          if ($p->validate_ipn()) {

              $complete = mysqli_query($db, "UPDATE matches SET status = '2'");

        }
          break;
     }     

    ?>

我已經嘗試了在StackOverflow上找到的多個修復程序。 大多數情況下是代碼編輯,但我認為這可能不是問題。 我嘗試禁用防火牆,以查看是否最終阻止了某些PayPal IP。 但這不是問題。

我也嘗試了PHP 5.3.8和PHP 7.2.7,但都沒有用,我在Windows 2016 VPS的IIS 10上運行了此腳本。 我還在網站上使用SSL證書,但也嘗試過不使用它。

我知道IPN URL是正確的,因為它可以完成我想要的所有事情,除了驗證IPN。 但是價格是正確的,付款會通過。 如您所見,查詢$ problem甚至執行,但查詢$ complete不執行,這就是我所需要的。

有人知道這可能是由什么引起的嗎?

2月份的Paypal電子郵件:

Quote:“”我們還鼓勵您與網絡托管公司,電子商務軟件提供商或內部網絡程序員/系統管理員聯系,以在實施這些更改時獲得進一步的幫助(如果需要的話)。此電子郵件中以及在TLS 1.2和HTTP / 1.1升級微型站點可能會有所更改,請監視我們的TLS 1.2和HTTP / 1.1升級微型站點以獲取最新信息。以下是一些有關安全更新的關鍵點,我們將於6月30日后開始實施,2017年,我們強烈建議您與系統兼容,以確保您的業務不中斷:•PayPal沙盒或測試環境已升級為僅允許TLS 1.2和HTTP / 1.1連接•所有生產終結點都將更新為接受2017年6月30日之后只能使用TLS 1.2和HTTP / 1.1連接。請注意,如果您尚未對系統進行必要的升級以使其合規,則您的企業將無法接受通過 貝寶(PayPal),直到進行了所需的更改為止。 •可以使用驗證端點,可以在https://tlstest.paypal.com上找到該端點,並具有最新的安全標准,因此客戶可以快速檢查其系統是否准備在2017年6月30日之后接受交易。”

Quote:“到HTTPS的IPN驗證回發–在2017年6月30日之前完成需要更新:是”

Micah暫時沒有更新他的腳本,但是這個腳本應該對您有用https : //github.com/xtuc/Paypal-ipn-SDK/blob/master/paypal.class.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM