PayPal NVP API - TransactionSearch 错误 10001 超时处理请求

PayPal NVP API - TransactionSearch Error 10001 Timeout processing request

我正在尝试使用 PayPal NVP API 构建自定义会计报告,它将获取特定日期范围内的所有交易。

我的代码:

$headers            = array(
    'USER'              => $production_user,
    'PWD'               => $production_pass,
    'SIGNATURE'         => $production_sig
);

$nvp                = array(
    'METHOD'            => 'TransactionSearch',
    'TRANSACTIONCLASS'  => 'RECEIVED',
    'STARTDATE'         => '2016-12-01T00:00:00Z',
    'ENDDATE'           => '2016-12-31T00:00:00Z'
);

$request_url        = "https://api-3t.paypal.com/nvp?".http_build_query($nvp);

$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
$result = curl_exec($curl);

$result = explode("&", $result);

foreach($result as $f=>$v){
    $t  = explode("=", $v);
    echo $t[0]." => ".urldecode($t[1]);
    echo "<br>";
}

这是打印的内容:

HTTP/1.1 200 OK Date: Fri, 10 Feb 2017 19:51:20 GMT Server: Apache X-PAYPAL-OPERATION-NAME: X-PAYPAL-API-RC: 10001 Connection: close Cache-Control: max-age => 0, no-cache, no-store, must-revalidate Pragma: no-cache HTTP_X_PP_AZ_LOCATOR: slcb.slc Paypal-Debug-Id: 484a759b46e4a Set-Cookie: X-PP-SILOVER

CORRELATIONID => some_random_characters
ACK => Failure
L_ERRORCODE0 => 10001
L_SHORTMESSAGE0 => Internal Error
L_LONGMESSAGE0 => Timeout processing request

非常感谢对此问题的任何帮助!

您正在使用 post 请求并且没有 post 数据。

我不知道 PayPal 希望看到什么,但我猜这不是您发送的内容。

一些尝试:

如果您需要在请求中传递 USER、PWD 和 SIGNATURE Header,请这样做:

$request = array();
$request[] = "USER: $production_user";
$request[] = "PWD: $production_pass";
$request[] = "SIGNATURE: $production_sig";

curl_setopt($ch, CURLOPT_HTTPHEADER, $request);

如果$nvp参数需要post数据,试试这个:

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp);

$nvp 也可以在 post 数据中作为查询字符串传递。

$query = http_build_query($nvp);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);

区别在于Content-Type.

第一种方法:

Content-Type: application/x-www-form-urlencoded 

第二种方法:

Content-Type: multipart/form-data

为了帮助解决问题,最好同时查看请求和响应 header。

使用这些选项获取 headers:

curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

请求 Header 将在 'curl_getinfo()'

curl_setopt($ch, CURLOPT_HEADER, true);


$result = curl_exec($ch);
$info = curl_getinfo($ch);
var_export($info);

上面给出了请求的许多其他细节。如果您只想查看 header:

 $request = curl_getinfo($ch, CURLINFO_HEADER_OUT);

获取响应header:

$result = curl_exec($ch);

$skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE)); 
$response = substr($result ,0,$skip);
$result = substr($result ,$skip);