我正在测试一个PayPal ipn监听器,它似乎永远不会返回VERIFIED状态......这是脚本:
<?php
//read the post from PayPal system and add 'cmd'
$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.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host:www.sandbox.paypal.com\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
//
//error connecting to paypal
if (!$fp) {
//
}
//successful connection
if ($fp) {
fputs ($fp, $header . $req);
//while (!feof($fp)) {
$res = stream_get_contents($fp, 1024);
//$res = fgets ($fp, 1024);
$res = trim($res); //NEW & IMPORTANT
if (strcmp($res, "VERIFIED") == 0) {
// if status is COMPLETED insert order into database
if ($_POST['payment_status'] == "Completed") {
$subject = 'Instant Payment Notification - COMPLETED';
$to = 'my_email_address@gmail.com'; // your email
$body = "An instant payment notification was successfully recieved\n";
$body .= "from ".$_POST['payer_email']." on ".date('m/d/Y');
$body .= " at ".date('g:i A')."\n\nDetails:\n";
foreach ($_POST as $key => $value) { $body .= "\n".$key." : ".$value; }
mail($to, $subject, $body);
}
}
else {
//insert into DB in a table for bad payments for you to process later
$subject = 'Instant Payment Notification - ELSE status';
$to = 'my_email_address@gmail.com'; // your email
$body = "Else clause \n";
$body .= "from ".$_POST['payer_email']." on ".date('m/d/Y');
$body .= " at ".date('g:i A')."\n\nDetails:\n";
foreach ($_POST as $key => $value) { $body .= "\n".$key." : ".$value; }
mail($to, $subject, $body);
}
//}
fclose($fp);
}
?>
我用 while(!feof($ fp))和 $ res = fgets($ fp,1024)尝试了代码 我从来没有收到过验证的电子邮件,我甚至不确定这是否是编码问题......这就是我在这里问的原因:也许你们中的一些人之前遇到过这个问题,可以帮助我。提前谢谢。
好的,这是$ res贴回来的:
HTTP/1.1 200 OK
Date: Wed, 26 Feb 2014 12:03:23 GMT
Server: Apache
domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: cookie_check=yes; expires=Sat, 24-Feb-2024 12:03:24 GMT;domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navlns=0.0; expires=Fri, 26-Feb-2016 12:03:24 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: Apache=10.72.109.11.1393416203743713; path=/; expires=Fri, 19-Feb-44 12:03: