Paypal IPN未验证或无效

时间:2017-12-16 19:04:56

标签: php paypal paypal-sandbox paypal-ipn

希望有人能够帮助我或指出我正确的方向。我已经设置了Paypal IPN监听器,但在确认使用paypal付款后似乎没有从paypal获得任何响应(已验证/无效)

我知道代码在某种程度上起作用,因为IPN History页面确认已从侦听器接收到响应,因此paypal不会尝试重新发送消息。如果我将一个代码片段插入到已验证/无效的if语句之外的数据库中,它可以正常工作。当我在验证/无效循环中放置相同的代码片段时,它不会做任何事情。

我用于监听器的PHP代码如下:

希望有人能够帮助我或指出我正确的方向。我已经设置了Paypal IPN监听器但是 在确认使用paypal付款后似乎没有从paypal获得任何回复(已验证/无效)

我知道代码在某种程度上起作用,因为IPN History页面确认已从侦听器接收到响应 所以paypal不会尝试重新发送消息。如果我将一个代码段放在已验证/无效之外的数据库中 如果声明它工作正常。当我在验证/无效循环中放置相同的代码片段时,它不会做任何事情。 我用于监听器的PHP代码如下:

<?php
// STEP 1 - be polite and acknowledge PayPal's notification
header('HTTP/1.1 200 OK');
// STEP 2 - create the response we need to send back to PayPal for them to confirm that it's legit
$resp = 'cmd=_notify-validate';
foreach ($_POST as $parm => $var)
{
$var = urlencode(stripslashes($var));
$resp .= "&$parm=$var";
}

// STEP 3 - Extract the data PayPal IPN has sent us, into local variables
$record_id = $_POST['custom'];
$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'];
// STEP 4 - Get the HTTP header into a variable and send back the data we received so that PayPal can confirm it's genuine
$httphead = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$httphead .= "Content-Type: application/x-www-form-urlencoded\r\n";
$httphead .= "Content-Length: " . strlen($resp) . "\r\n\r\n";

// Now create a ="file handle" for writing to a URL to paypal.com on Port 443 (the IPN port)
$errno ='';
$errstr='';

//$fh = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fh = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
// STEP 5 - Nearly done. Now send the data back to PayPal so it can tell us if the IPN notification was genuine

if (!$fh) {
}
else {
fputs ($fh, $httphead . $resp);
while (!feof($fh))
{
$readresp = fgets ($fh, 1024);
if (strcmp ($readresp, "VERIFIED") == 0)
{

}

else if (strcmp ($readresp, "INVALID") == 0)
{

}
}
fclose ($fh);
}
?>

0 个答案:

没有答案