调用 PayPal CreateInvoice API 的代码。它总是失败说“无效请求”并得到errorId 580001。我浏览了几次填充请求和API文档的代码。不知道 Request 中的哪些数据是错误的。请求中可能有什么问题?我在这里错过了什么吗?
function getInvoiceAPIHeader()
{
global $API_Username, $API_Password, $Signature;
$API_Username = $this->config['username'];
$API_Password = $this->config['password'];
$Signature = $this->config['signature'];
$headers[0] = "Content-Type: text/namevalue"; // either text/namevalue or text/xml
$headers[1] = "X-PAYPAL-SECURITY-USERID: $API_Username"; //API user
$headers[2] = "X-PAYPAL-SECURITY-PASSWORD: $API_Password"; //API PWD
$headers[3] = "X-PAYPAL-SECURITY-SIGNATURE: $Signature"; //API Sig
$headers[4] = "X-PAYPAL-APPLICATION-ID: {$this->APPLICATION_ID}"; //APP ID
$headers[6] = "X-PAYPAL-REQUEST-DATA-FORMAT: ".self::REQUEST_DATA_FORMAT.""; //Set Name Value Request Format
$headers[7] = "X-PAYPAL-RESPONSE-DATA-FORMAT: ".self::RESPONSE_DATA_FORMAT.""; //Set Name Value Response Format
Debugger::dump($headers);
return $headers;
}
function curlRequest($str_req)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->end_url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getInvoiceAPIHeader());
curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response, use for testing
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, TRUE);
// setting the NVP $my_api_str as POST FIELD to curl
$log_req = $aryRresponse = explode("&", $str_req);
var_dump($log_req);
curl_setopt($ch, CURLOPT_POSTFIELDS, $str_req);
// getting response from server
$httpResponse = curl_exec($ch);
//var_dump($httpResponse);
if(!$httpResponse)
{
Debugger::dump("no response");
$response = "{$this->end_url} failed: ".curl_error($ch)."(".curl_errno($ch).")";
return $response;
}
$aryRresponse = explode("&", $httpResponse);
var_dump($aryRresponse);
return $httpResponse;
}
请求转储:
array(
(int) 0 => 'Content-Type: text/namevalue',
(int) 1 => 'X-PAYPAL-SECURITY-USERID: stest_1339339519_biz_api1.paypal.com',
(int) 2 => 'X-PAYPAL-SECURITY-PASSWORD: 1339339539',
(int) 3 => 'X-PAYPAL-SECURITY-SIGNATURE: A2I9zTt-d7IIbjVBlzNeLjVm9UJxAPoaKvgzcIz6c6G1-sLSKn5jcI3b',
(int) 4 => 'X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T',
(int) 6 => 'X-PAYPAL-REQUEST-DATA-FORMAT: NV',
(int) 7 => 'X-PAYPAL-RESPONSE-DATA-FORMAT: NV'
)
array
0 => string 'invoice.merchantEmail=stest_1339339519_biz%40paypal.com' (length=55)
1 => string 'invoice.payerEmail=stest_1340973819_per%40paypal.com' (length=52)
2 => string 'invoice.currencyCode=USD' (length=24)
3 => string 'invoice.number=PP-99' (length=20)
4 => string 'invoice.paymentTerms=Net10' (length=26)
5 => string 'invoice.itemList.item%281%29.name=Coke' (length=38)
6 => string 'invoice.itemList.item%281%29.description=From+CocaCola' (length=54)
7 => string 'invoice.itemList.item%281%29.quantity=2' (length=39)
8 => string 'invoice.itemList.item%281%29.unitPrice=01.65' (length=44)
9 => string 'invoice.itemList.item%281%29.taxName=Tax1' (length=41)
10 => string 'invoice.itemList.item%281%29.taxRate=7' (length=38)
响应转储:
array
0 => string 'HTTP/1.1 200 OK
Date: Mon, 02 Jul 2012 17:06:05 GMT
Server: Apache-Coyote/1.1
CACHE-CONTROL: no-cache
X-PAYPAL-MESSAGE-PROTOCOL: NONE
X-PAYPAL-RESPONSE-DATA-FORMAT: NV
X-EBAY-SOA-REQUEST-ID: 13848a7f-b860-a486-d656-c516ffffc6d8!Invoice!10.72.109.101![]
X-PAYPAL-OPERATION-NAME: CreateInvoice
X-PAYPAL-SERVICE-NAME: {http://svcs.paypal.com/types/pt}Invoice
X-PAYPAL-SERVICE-VERSION: 1.0.0
X-PAYPAL-ERROR-RESPONSE: TRUE
Content-Type: text/plain;charset=UTF-8
Set-Cookie: Apache=10.72.109.11.13412487648'... (length=679)
1 => string 'responseEnvelope.ack=Failure' (length=28)
2 => string 'responseEnvelope.correlationId=4cab848d7c2a0' (length=44)
3 => string 'responseEnvelope.build=2910623' (length=30)
4 => string 'error(0).errorId=580001' (length=23)
5 => string 'error(0).domain=PLATFORM' (length=24)
6 => string 'error(0).subdomain=Application' (length=30)
7 => string 'error(0).severity=Error' (length=23)
8 => string 'error(0).category=Application' (length=29)
9 => string 'error(0).message=Invalid+request%3A+%7B0%7D' (length=43)
请求中可能有什么问题?任何指针?