使用cURL和PHP的PayPal IPN INVALID结果

时间:2016-05-21 17:26:48

标签: php curl paypal

我已经在Stackoverflow中查询了很多(如果不是全部)问题以获得答案,我找不到它。

我遇到PayPal IPN问题。我正在使用sanbox和IPN Simulator进行测试。我也使用PHP和cURL验证来自PayPal的响应。但我只得到INVALID响应的结果。我似乎无法获得验证。

我认为问题在于我没有将确认网址发送回PayPal。您可以在下面看到我的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}')");
}?> 

1 个答案:

答案 0 :(得分:1)

我终于明白了。问题INVALID是因为发送的TIME等于GMT + 3而使其无效。在我没有使用+ 3将其更改为GMT之后,它已经工作,返回验证。

但问题是为什么当我使用GMT + 3时它返回INVALID我怎样才能使它与GMT + 3一起使用?