我正在尝试让这个PayPal IPN脚本工作,但似乎我没有得到贝宝的回应。我不知道有什么问题,是在表单中还是在脚本中:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input name="return" type="hidden" value="http://localhost/home/menu/index.php" />
<input name="cancel_return" type="hidden" value="http://localhost/home/menu/index.php" />
<input name="notify_url" type="hidden" value="http://localhost/home/menu/php/inni.php" /> 这是脚本inni.php:
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$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);
$item_name = $_POST['item_name'];
if (!$fp) {
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// vérifier que payment_status a la valeur Completed
if ( $payment_status == "Completed") {
if ( $email_account == $receiver_email) {
//insert in db
}
}
else {
// Statut de paiement: Echec
}
exit();
}
else if (strcmp ($res, "INVALID") == 0) {
// Transaction invalide
}
}
fclose ($fp);
} 发布于 2014-06-15 06:26:17
问题是您正在向本地主机发送PayPal。
将链接(notify_url)更改为可公开访问的URL或IP地址。
PayPal从它们的服务器发送通知,因此发送到本地主机的通知不会到达本地主机,在这种情况下,本地主机将是PayPal服务器本身。
发布于 2020-06-10 14:21:07
您需要将PayPal IPN请求转发到本地计算机才能正常工作。有几个项目在处理这一点,既有免费的,也有商业的。
免费和开源的变体是:https://github.com/antoniomika/sish
一个商业变体:https://ngrok.com/
Ngrok的实现速度更快一些,因为您不需要配置服务器。
使用Ngrok将http请求转发到localhost
./ngrok http -host-header=localhost 80然后在浏览器中打开
http://localhost:4040/inspect/http从状态页复制您的ngrok url
https://d1c7361aebf0.ngrok.io假设您的IPN通知url是
https://www.example.com/api/paypal-ipn更新并开始测试即时支付通知
https://d1c7361aebf0.ngrok.io/api/paypal-ipn注意:请确保关闭所有与域名相关的重定向,使其正常工作。
https://stackoverflow.com/questions/24224196
复制相似问题