我已經查看了很多(如果不是所有的問題都在Stackoverflow中),爲此我找不到答案。PayPal IPN INVALID使用cURL和PHP的結果
我遇到PayPal IPN問題。我正在使用sanbox和IPN模擬器測試它。我還使用PHP和cURL來驗證來自PayPal的響應。但是我只得到了無效的響應結果。我似乎無法驗證。
我認爲問題在於我沒有將確切的URL發送回貝寶。你可以看到我的IPN聽衆的代碼如下:
<?php
require_once('../includes/main.php');
// Prepare the URL to send via cURL
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($_POST as $key => $value) {
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}
// Initial cURL
$ch = curl_init();
// Set opt
curl_setopt($ch,CURLOPT_URL,"https://www.sandbox.paypal.com/cgi-bin/webscr");
//curl_setopt($ch,CURLOPT_URL,"https://www.paypal.com");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
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_FORBID_REUSE, 1);
// Return result
$result = curl_exec($ch);
// Close cURL connection
curl_close($ch);
// If condition
if(strpos($result, "VERIFIED") != false){
mysql_query("INSERT INTO paypal_ipn (ipn_message, verification) VALUES ('{$request}', '{$result}')");
}else{
mysql_query("INSERT INTO paypal_ipn (ipn_message, verification) VALUES ('{$request}', '{$result}')");
}?>
如果我知道如何比較網址,我可能會解決問題。但我不知道如何獲取網址。 – FarrisFahad
你有'var_dump($ result)'看看裏面有什麼? – frz3993
@ frz3993我剛剛做到了,'var_dump'等於NULL。並且結果仍然無效 – FarrisFahad