通过API从Paypal获取交易信息


Getting Transaction Information From Paypal through API

我正在尝试使用paypal的API使用此代码获得旧的交易细节:

<?php 
$info = 'USER=[username]'
        .'&PWD=[password]'
        .'&SIGNATURE=[signature]'
        .'&METHOD=TransactionSearch'
        .'&TRANSACTIONCLASS=RECEIVED'
        .'&STARTDATE=2014-01-01T05:38:48Z'
        .'&ENDDATE=2014-01-02T05:38:48Z'
        .'&VERSION=94';
$curl = curl_init('https://api-3t.sandbox.paypal.com/nvp');
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_POSTFIELDS,  $info);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
$result = curl_exec($curl);
if($result == FALSE) { 
    echo "cURL error: " . curl_error($curl);
}
parse_str($result, $result);
foreach($result as $key => $value){
    echo $key.' => '.$value."<BR>";
}

我得到一个错误信息:

TIMESTAMP => 2014-07-01T10:57:55Z
CORRELATIONID => db47001bb195b
ACK => Failure
VERSION => 94
BUILD => 11562053
L_ERRORCODE0 => 10002
L_SHORTMESSAGE0 => Security error
L_LONGMESSAGE0 => Security header is not valid
L_SEVERITYCODE0 => Error

这段代码的最终结果是在事务记录中搜索特定的事务,并将该数据转发给程序的其余部分。

无效的安全头错误几乎总是与您的API凭据不正确有关。仔细检查您的API用户名、密码和签名。另外,当您从沙箱迁移到活动环境时,请务必更改凭据。