嗨,我知道有很多问题已经在与我的问题有关,但我没有得到任何解决方案。我已经实现了paypal。它运作良好。现在我想在我的PayPal实现中实现ipn。我已经搜遍并找到一些代码。我已经实现了,但我越来越无效ipn。我可以从贝宝交易中获得所有细节,但对于ipn,它总是无效的。我用下面的代码在DoExpressCheckoutPayment.php文件贝宝:无效的IPN问题
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
// If testing on Sandbox use:
$header .= "Host: www.sandbox.paypal.com:443\r\n";
//$header .= "Host: www.paypal.com:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp =fsockopen('ssl://www.sandbox.paypal.com',443,$err_num,$err_str,30);
echo('<br>'.$req);
// assign posted variables to local variables
/*$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'];*/
if (!$fp)
{
echo(' HTTP ERROR');
}
else
{
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
echo('<br> res is '.$res);
if (strcmp ($res, "VERIFIED") == 0)
{
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$mail_From = "From: [email protected]";
$mail_To = "[email protected]";
$mail_Subject = "VERIFIED IPN";
$mail_Body = $req;
foreach ($_SESSION as $key => $value)
{
$emailtext .= $key . " = " .$value ."\n\n";
}
if(mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From))
echo('<br>mail 1 sent');
else
echo('<br>mail1 not sent');
}
else if (strcmp ($res, "INVALID") == 0)
{
// log for manual investigation
$mail_From = "From: [email protected]";
$mail_To = "[email protected]";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;
foreach ($_SESSION as $key => $value)
{
$emailtext .= $key . " = " .$value ."\n\n";
}
if(mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From))
echo('<br>mail sent');
else
echo('<br>not sent');
}
}
fclose ($fp);
}
我设置的其他文件notify_url其定向到这个文件中像这样
<input type="hidden" name="notify_url" value="http://www.mysite.com/paypal/DoExpressCheckoutPayment.php"/>
我得到以下电子邮件:
**notify_url = http://www.mysite.com/paypal/DoExpressCheckoutPayment.php
cmd=_notify-validate¬ify_url=http%3A%2F%2Fwww.mysite.com%2Fpaypal%2FDoExpressCheckoutPayment.php**
有一件事我注意到我没有从$ _POST获取任何东西。我的$ _POST是空的。 请告诉我我错在哪里。 谢谢
什么不工作?像这样的东西很少可以通过查看代码来排序,而是通过在实时环境中进行调试。 – 2011-03-19 09:09:18
你是否去过你的paypay配置文件并将ipn设置为on? https://www.paypal.com/cgi-bin/customerprofileweb?cmd=_profile-ipn-notify – 2011-03-19 09:11:07
@Awais - 尝试将电子邮件功能放在有效/无效语句之外,并将自己收到的$ req字符串发送给自己PP。然后你可以看看为什么它没有被正确处理。 – Kit 2011-03-19 09:34:00