2015-04-24 62 views
2

我嘗試在事務完成時向數據庫中插入新條目。所以我在我的服務器上創建了這個IPN監聽器腳本:貝寶IPN模擬器不工作?

<?php 

include 'MessageManager.php'; 

// STEP 1: read POST data 
// Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. 
// Instead, read raw POST data from the input stream. 
$raw_post_data = file_get_contents('php://input'); 
$raw_post_array = explode('&', $raw_post_data); 
$myPost = array(); 
foreach ($raw_post_array as $keyval) { 
    $keyval = explode ('=', $keyval); 
    if (count($keyval) == 2) 
    $myPost[$keyval[0]] = urldecode($keyval[1]); 
} 
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' 
$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"; 
} 
$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr'); 
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $req); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close')); 
if(!($res = curl_exec($ch))) { 
    error_log("Got " . curl_error($ch) . " when processing IPN data"); 
    curl_close($ch); 
    exit; 
} 
curl_close($ch); 

if (preg_match("!(VERIFIED)\s*\Z!",$res)){ 
    // assign posted variables to local variables 
    $item_name = $_POST['item_name']; 
    $payment_status = $_POST['payment_status']; 
    $payment_amount = $_POST['mc_gross']; 
    $quantity = $_POST['custom']; 
    $receiver_email = $_POST['receiver_email']; 

    if($payment_status === "Completed"){ 
     addMessage($item_name,(int) $quantity , $payment_amount); 
    } else { 
    } 

} else { 
} 
?> 

這是基於PayPal提供的腳本。我正在使用IPN模擬器來測試腳本。該腳本應該在完成銷售後在我的數據庫中插入一個新條目。插入代碼本身運行良好,但是當我運行模擬器時,它表示在貝寶sute上成功,但是在我的數據庫中沒有新條目。

有什麼我做錯了嗎?

編輯:我收到此錯誤信息:

失敗1SSL證書問題

比你的時間。

回答

2

嘗試關閉ssl驗證選項。我檢查了我的IPN腳本,它在那裏。有some caveats這個,但它應該是安全的,因爲你連接到貝寶並驗證數據。

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
+0

好吧,工作:)但是,這確實是一些安全問題。但正如你所說的那樣安全。謝謝 – TastyLemons