2012-05-07 61 views
2

我的主機已啓用php 5.0和SSL,但嚴格淘汰在線論壇和博客後,我不能爲我的生活弄清楚爲什麼即時通信返回與PayPal IPN腳本即時空嘗試使用。我正在使用沙箱模擬器來測試腳本,因此沒有骰子來檢索Post數據。請參閱我下面的代碼 -掙扎接收PayPal沙盒IPN發佈數據

$header = ''; 

$req = 'cmd=_notify-validate'; 

foreach($_POST as $key => $value) { 
    //All PayPal reqs must be URL encoded 
    $value = urlencode(stripslashes($value)); 
    //Append key => value pair to CMD string 
    $req .= "&$key=$value"; 
} 


//Post info back to paypal for verification 
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; 
// $header .= "Host: ssl://www.sandbox.paypal.com\r\n"; 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 
//$header .= "Connection: Close\r\n"; 
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); 

$con=mysql_connect("localhost","quadsour_xswitch","xswitch"); 
mysql_select_db("quadsour_xswitch",$con);//$data="NULL" 

if(!$fp) { 
    //Process HTTP Error 
    $filename = 'debug.txt'; 
    $filehandle=fopen($filename, 'w'); 
    fwrite($filehandle, $errstr.'('.$errno.')'); 
    fclose($filehandle); 
    die(); 

$message .= "\n HTTP ERROR. \n"; 

} else { 
    fputs ($fp, $header . $req); 
    while (!feof($fp)) { 
     $res = stream_get_contents($fp, 1024); 
     /* $data="INSERT INTO ipn SET 
     complete='".$errstr."',invoice='".$errno."'"; 
     $query=mysql_query($data); 
     */ 

     //VERIFIED TRANSACTION 
     //PAYMENT 
     if($_POST['payment_status'] == 'completed') { 
      $data="INSERT INTO ipn SET 
      complete='cond'"; 
      $query=mysql_query($data); 

      $data="INSERT INTO ipn SET 
      complete='true', 
      invoice='".$_POST['invoice']."', 
      email='".$_POST['payer_email']."' 
      "; 
      $query=mysql_query($data); 

      //$subscription = //Do SQL to retrieve the subscription based on $_POST['invoice'] 


     } 

    } 

    fclose ($fp); 
} 
+0

錯誤日誌中的任何錯誤? –

+0

檢查paypal上的日誌,它爲IPN呼叫提供了什麼狀態碼? –

回答

1

至於誰寫了幾個PHP庫的使用PayPal IPN(以下笨和Symfony2中的)工作的人,我不得不說,你的腳本是遠不足夠的處理PayPal IPN的所有可能性都以安全可靠的方式進行。

而不是另起爐竈,只需插上這些庫之一,這取決於你的PHP設置: