Php Paypal:无效的IPN问题
您好,我知道有很多问题已经在这么相关的我的问题,但我没有得到解决,从他们中的任何一个。我已经实现了贝宝。它运行良好。现在我想在我的paypal实现中实现ipn。我搜索了一下,找到了一些代码。我已经实现了,但是我得到了无效的ipn。我可以从paypal交易中获得所有细节,但对于ipn来说,它总是无效的。我在DoExpressCheckoutPayment.php文件中使用了以下代码Php Paypal:无效的IPN问题,php,paypal,Php,Paypal,您好,我知道有很多问题已经在这么相关的我的问题,但我没有得到解决,从他们中的任何一个。我已经实现了贝宝。它运行良好。现在我想在我的paypal实现中实现ipn。我搜索了一下,找到了一些代码。我已经实现了,但是我得到了无效的ipn。我可以从paypal交易中获得所有细节,但对于ipn来说,它总是无效的。我在DoExpressCheckoutPayment.php文件中使用了以下代码 $req = 'cmd=_notify-validate'; foreach ($_POST as $key =&
$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: me@mybiz.com";
$mail_To = "xxxx@gmail.com";
$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: me@mybiz.com";
$mail_To = "xxx@gmail.com";
$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 = http://www.mysite.com/paypal/DoExpressCheckoutPayment.php
cmd=_notify-validate¬ify_url=http%3A%2F%2Fwww.mysite.com%2Fpaypal%2FDoExpressCheckoutPayment.php**
我注意到的一件事是,我没有从$\u POST得到任何东西。我的$\u帖子是空的。
请告诉我哪里错了。
谢谢请在此处尝试此代码。它与您上面使用的略有不同。它对我有用
<?php
$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";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// 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) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
//Process Order
}else if (strcmp ($res, "INVALID") == 0) {
//Send Email To You
}
}
fclose ($fp);
}
?>
作为返回链接提供的URL被调用2次!第一次来自PayPal并发送POST数据时,第二次重定向用户。您将看到一些GET变量,但它们非常无用(至少对于请求事务而言)
查看POST数据是否(在第一个请求中)的唯一方法是使用错误日志或类似的东西。什么不起作用?像这样的东西很少可以通过查看代码来分类,而是通过在实时环境中进行调试来分类。您是否访问过您的paypay配置文件并将ipn设置为on@Awais-尝试将电子邮件功能置于有效/无效语句之外,并将从PP收到的
$req
字符串发送给您自己。然后您可以检查它未被正确处理的原因。@pekka。我收到了一封无效的电子邮件ipn@Awais-您的脚本发回包含PP发送的所有IPN变量的数据。PP然后发回有效或无效的响应,说明您收到的数据是否为合法付款。你能将无效电子邮件的内容粘贴到pastebin.com吗?@Christopher。但是哥们儿,邮局里什么都没有$_邮件是空的。好的,告诉我一件事,$\u POST中的值是由PP设置的还是由我设置的?如果它是由PP设置的,那么我什么也得不到。如果是我设置的,请告诉我在哪里设置这些?您收到的无效电子邮件是否包含$req
字符串的内容?是的,这是cmd=\u notify-validate¬ify\u url=http%3A%2F%2Fwww.mysite.com/paypal%2FDoExpressCheckoutPayment.phpAfraid我不太确定。。我能想到的最后一件事是确保您从IPN测试仪发送了正确的IPN。还有,你想把它发送给你的本地主机吗?@Christopher。尝试了您的代码,但没有任何post数据。并且有同样的反应
<?php
$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";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// 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) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
//Process Order
}else if (strcmp ($res, "INVALID") == 0) {
//Send Email To You
}
}
fclose ($fp);
}
?>