我一直在尝试为我正在尝试构建的网站配置IPN。简而言之,我希望这可以控制我的数据库条目,以及其他API来将命令放在别处。
我无法让它发挥作用。检查PayPal网站上的IPN历史记录看起来好像正在向URL发送(我在按钮中指定,而不是通过Paypal),但绝对没有任何反应。从我的脚本中,我希望收到一封电子邮件,说明失败或成功。我也尝试在我的listener.php中设置一个会话变量,我在返回的URL上检查(虽然我认为由于IPN而没有设置,并且返回页面不一定连续运行)...
无论如何,有人能够把目光投向我所拥有的东西,让我知道我哪里出错了,因为我一直把头发拉过来!
<?php
// listener.php
$_SESSION['listener'] = 'reached';
// read the post from PayPal
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$header .= "Conection: Close";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
}
else {
fputs ($fp, $header . $req);
$res = stream_get_contents($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
$to = 'myemail@gmail.com';
$subject = 'IPN VERIFIED';
$message = $req;
$headers = 'From:noreply@mydomain.com' . "\r\n";
mail($to, $subject, $message, $headers);
}
else if (strcmp ($res, "INVALID") == 0) {
$to = 'mymail@gmail.com';
$subject = 'IPN INVALID';
$message = $req;
$headers = 'From:noreply@mydomain.com' . "\r\n";
mail($to, $subject, $message, $headers);
}
fclose ($fp);
}
?>
如果我需要提供更多详细信息,请与我们联系。
我已经通过电子邮件向我自己检查了$res
的价值,虽然我期待“验证”或“无效”,但实际上我有这个:
HTTP/1.1 200 OK Date: Mon, 11 Aug 2014 09:14:48 GMT Server: Apache X-Frame-Options: SAMEORIGIN Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=3B4lq1GFXyCeV6nNKFDjhiS0CC1T77tsq9IXk6bQiM3OI8T1hI6ih0f7I0FDZQH3e6lqT0RXEH4DqKZUJ9uKzNyIxPANl_6326ntzQsqsVA_2KO7z0wvIKf_T_9BwLagSrsP7r7X5TO3G15FCnUK-PIqOlv16zGTZrmLood4Ezql7U17t2emfzW_CfbgFDDZogUFvIUhjCqzN1pLiejHhgKADJj0jNpmjOeMXdY9XWtytXo9NWUH0OuAlrsoYaU3beBi2MK86WLaZnSNBxbrpVOG9W70_lS8fxJ5QPA1K-jXhBAf3p4eqKXzoKOeEqNOCeKEnemyqxrhkQx8lUBnTWo_BdBfMinfEhqfyisMv13mwLixHKKJ9Kkd3jRQGFwW0139gBT4Hw_hUvbJ2AfLVxKeFrfb64x10B3C8Y8rb8bJ6nrwUm7-DJS-3He; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: cookie_check=yes; expires=Thu, 08-Aug-2024 09:14:49 GMT; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: navlns=0.0; expires=Wed, 10-Aug-2016 09:14:49 GMT; domain=.paypal.com; path=/; Secure; HttpOnly Set-Cookie: Apache=10.72.109.11.1407748488825362; path=/; expires=Wed, 03-Aug-44 09:14:
非常感谢! 利