1
我使用貝寶IPN下面的代碼:貝寶IPN沒有得到證實
<?php
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("PayPal") or die(mysql_error());
// 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.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.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// PAYMENT VALIDATED & VERIFIED!
}
else if (strcmp ($res, "INVALID") == 0) {
// PAYMENT INVALID & INVESTIGATE MANUALY!
}
}
fclose ($fp);
}
?>
在所有可能的方法測試後,我得到的一切,除了上班的時候:
if (strcmp ($res, "VERIFIED") == 0)
不工作
if (strcmp ($res, "VERIFIED") == 1)
WORKS
很明顯,它沒有得到驗證,因爲我從沙箱發送IPN。
什麼可能會丟失?
如果您處於沙箱模式,請在'fsockopen的hostname參數中使用'ssl:// www.sandbox.paypal.com'而不是'ssl:// www.paypal.com' '。 – Josh