我已經要求我的PayPal API發送$ res的電子郵件以查看回復是什麼。在while(!FEOF($ FP))的{}PayPal IPN不返回驗證爲0
這就是我從$越來越RES給我的電子郵件
HTTP/1.0 400 Bad Request
Server: BigIP
Connection: close
Content-Length: 19
Invalid Host header
這是我的PayPal代碼。
$req = 'cmd=_notify-validate';
$req .= payment_safe_check ($_POST);
$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";
$mode = strtolower($paymod_data['PAYMENT_MODE']);
mail("to email", "subject",serialize($_POST));
if ($mode == 'test')
{
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
}
else
{
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
}
if (!$fp)
{
// HTTP ERROR
die ("Error");
}
else
{
// NO HTTP ERROR
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0)
{
processing ($_POST);
}
else if (strcmp ($res, "INVALID") == 0)
{
}
}
fclose ($fp);
}
這不起作用if (strcmp ($res, "VERIFIED") == 0){}
但如果我將其更改爲if (strcmp ($res, "VERIFIED") == -1){}
它工作正常。
UPDATE
我有我的代碼更改爲
$mode = $paymod_data['PAYMENT_MODE'];
$paypal_url = ($mode == 'test') ? 'www.sandbox.paypal.com' : 'www.paypal.com';
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval)
{
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
$req .= payment_safe_check ($_REQUEST);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$paypal_url.'/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: '.$paypal_url));
$res = curl_exec($ch);
curl_close($ch);
if (strcmp ($res, "VERIFIED") == 0) {
processing ($_POST);
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
有人請確認是否與此代碼的任何問題。
改變我的後代碼我得到了這個。 HTTP/1.0 400錯誤的請求 服務器:BIGIP 連接:關閉 的Content-Length:19 無效的主機頭 – user1561124
你知道什麼是新的貝寶IPN的代碼,我可以使用。這是最新的代碼https://www.x.com/instant-payment-notification-4 – user1561124