2013-02-21 129 views
0

页面上有贝宝按钮。有2个自定义字段与贝宝按钮。我在ipn.php页面上获得IPN响应。我从贝宝网站得到了这段代码。PHP - 贝宝IPN集成问题

当我使用SandBox进行测试时,支付是从买方帐户中推导出来的,并存入商家帐户。但是数据并没有被插入到我在下面最后提到的代码中提到的数据库表中。我也尝试在名为“custom”的单个变量中发送这两个变量值,但仍然没有运气。请检查我的代码,并让我知道我在做什么错误。请帮助我,因为我在过去的两天挣扎。

$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]); 
} 

$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 (strcmp ($res, "VERIFIED") == 0) { 
$item_name = $_POST['item_name']; 
$item_number = $_POST['item_number']; 
$payment_status = $_POST['payment_status']; 
$payment_amount = $_POST['mc_gross']; 
$payment_currency = $_POST['mc_currency']; 
$txn_id = $_POST['txn_id']; 
$receiver_email = $_POST['receiver_email']; 
$payer_email = $_POST['payer_email']; 
$custom_memname = $_POST['custom_memname']; // This is 1st custom variable 
$custom_mempass = $_POST['custom_mempass']; // This is 2nd custom variable 

$str_query_insert="insert into t_fmember(memberid,password) values('" .$custom_memname."','".$custom_mempass."')"; 
ExecuteQuery($str_query_insert); 
} 

我加入这个代码我ipn.php网页上使用IPN模拟器,但没有得到任何回应呢。

$post_data_string = serialize($_POST); 
mail('[email protected]', 'PayPal IPN', $post_data_string); 

如果可能,请进一步帮助。谢谢

+0

愚蠢的问题,但你知道,在沙箱模式PayPal不会发送IPN响应到您的服务器不是吗?您需要在开发人员工具中使用IPN模拟器。 – toomanyredirects 2013-02-21 10:39:46

+0

我接受问题的愚蠢,但我没有线索,所以我会做你的建议。非常感谢你。 – KRA 2013-02-21 10:45:48

+0

没问题。我已重新张贴为答案,如果这解决了您的问题,请接受。 – toomanyredirects 2013-02-21 10:47:35

回答