这是我的代码,凭据是正确的,为什么我的身份验证失败?它可能是标题,但我无法弄清楚哪个。
<?php
$ch = curl_init();
$headers = array("X-PAYPAL-SECURITY-USERID" => "--",
"X-PAYPAL-SECURITY-PASSWORD" => "--,
"X-PAYPAL-SECURITY-SIGNATURE" => "--",
"X-PAYPAL-APPLICATION-ID" => "APP-80W284485P519543T",
"X-PAYPAL-REQUEST-DATA-FORMAT" => "NVP",
"X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON",
"X-PAYPAL-SANDBOX-EMAIL-ADDRESS" => "--",
"Accept" => "application/json",
'Content-Type: application/x-www-form-urlencoded');
curl_setopt($ch, CURLOPT_URL, "https://svcs.sandbox.paypal.com/AdaptivePayments/ConvertCurrency");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "requestEnvelope.errorLanguage=en_US&
baseAmountList.currency(0).code=USD&
baseAmountList.currency(0).amount=1&
baseAmountList.currency(1).code=EUR&
baseAmountList.currency(1).amount=1&
baseAmountList.currency(2).code=SEK&
baseAmountList.currency(2).amount=1&
convertToCurrencyList.currencyCode=USD");
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
echo $result;
}
curl_close($ch);
?>
作为回报,我得到了这个:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-EBAY-SOA-REQUEST-ID: 144ee8af-72d0-a486-d657-e4f2fffe5f49!AdaptivePayments!10.72.109.101![]
X-PAYPAL-SERVICE-VERSION: 1.0.0
X-PAYPAL-SERVICE-NAME: {http://svcs.paypal.com/types/ap}AdaptivePayments
X-EBAY-SOA-RESPONSE-DATA-FORMAT: XML
X-PAYPAL-OPERATION-NAME: ConvertCurrency
Cache-Control: no-cache
X-PAYPAL-ERROR-RESPONSE: TRUE
X-EBAY-SOA-MESSAGE-PROTOCOL: NONE
Content-Type: text/xml;charset=UTF-8
DC: origin1-svcs.sandbox.paypal.com
Date: Sun, 23 Mar 2014 10:44:48 GMT
Transfer-Encoding: chunked
Connection: keep-alive
Connection: Transfer-Encoding
Set-Cookie: Apache=10.72.109.11.1395571488549095; path=/; expires=Tue, 15-Mar-44 10:44:48 GMT
Set-Cookie: DC=origin1-svcs.sandbox.paypal.com; secure
<?xml version='1.0' encoding='UTF-8'?><ns3:FaultMessage xmlns:ns3="http://svcs.paypal.com/types/common" xmlns:ns2="http://svcs.paypal.com/types/ap"><responseEnvelope><timestamp>2014-03-23T03:44:48.571-07:00</timestamp><ack>Failure</ack><correlationId>95445f07b579b</correlationId><build>10175386</build></responseEnvelope><error><errorId>520003</errorId><domain>PLATFORM</domain><subdomain>Application</subdomain><severity>Error</severity><category>Application</category><message>Authentication failed. API credentials are incorrect.</message></error></ns3:FaultMessage>
答案 0 :(得分:0)
您正在使用沙盒共享X-PAYPAL-APPLICATION-ID
,这对于沙箱是正确的,但不会在实时中使用。在那里,您需要自己的应用程序ID。
我的示例还包含标题"X-PAYPAL-SERVICE-VERSION": "1.0.0"
。