我已经使用完全相同的代码从贝宝,并尝试从PayPl沙箱从IPN模拟器得到响应。我在我的网站上设置了ipn.php文件,我将得到IPN响应,并具有下面的代码。仍然我没有得到任何邮件的VERIFIED或INVALID状态,如我在下面的代码中所述。所以请让我知道我的代码中缺少什么或者什么是错误的,所以我可以纠正它。Paypal沙箱IPN模拟器 - 没有得到回应
<?php
$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'];
mail('[email protected]', 'PayPal IPN', 'Working...');
}
else if (strcmp ($res, "INVALID") == 0)
{
// log for manual investigation
mail('[email protected]', 'PayPal IPN', 'NOT Working...');
}
?>
我曾尝试使用测试商家和买家,以测试帐户在贝宝沙箱。我可以看到IPN历史测试商家帐户。在那里我可以看到HTTP响应代码= 200,所以我想我的ipn脚本是通过贝宝访问的。 0.25美元的金额从买方账户中扣除并存入商业账户,所以我猜这部分工作正常。
现在我已经在单个变量中传递了2个值。
<input type="hidden" name="custom" value="mem001::mempass001">
然后,我试图接收我的ipn.php(ipn脚本在此页面上)页面上的“自定义”变量的值。使用PHP函数我已经分离了两个值并存储在不同的变量中。
为了测试目的,我试图在数据库中存储以上值,但值不存储到数据库中。
那么最后我到底做了什么错误?我怎样才能确保在上述所有流程之后,我真的从IPN获得“VERIFIED”状态?请帮忙。
你好,感谢您的回复。我检查了我的Windows Plesk控制面板,查看访问和错误日志,但找不到任何地方。你能指导如何访问它们吗? – KRA 2013-02-27 04:10:09
请忽略我的上述评论。我根据您的建议张贴答案,请回复。 – KRA 2013-02-27 06:00:07