使用PHP-curl: Security头无效


With PHP-curl: Security header is not valid

我正在使用这个PayPal Express Checkout API,但我得到一个错误:

ACK=Failure&VERSION=78&BUILD=000000&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Security%20error&L_LONGMESSAGE0=Security%20header%20is%20not%20valid&L_SEVERITYCODE0=Error
代码:

$request = 'USER=myuser.de&PWD=mypass&SIGNATURE=mysig&METHOD=SetExpressCheckout&VERSION=78&PAYMENTREQUEST_0_PAYMENTACTION=SALE&PAYMENTREQUEST_0_AMT=19&PAYMENTREQUEST_0_CURRENCYCODE=EUR&cancelUrl=http://xyz.biz/index.php?id=16&returnUrl=http://xyz.biz/abc/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api-3t.sandbox.paypal.com/nvp");
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec ($ch);
curl_close ($ch);

我能做什么?

安全头无效通常是由于您的API凭据输入错误。

curl_setopt($ch, CURLOPT_URL, "https://api-3t.sandbox.paypal.com/nvp");

看起来您正在发送到您的实时环境。请确保使用正确的凭据。

当我用我的凭据使用你的字符串和卷曲调用时,我得到一个积极的响应:

Array
(
    [TOKEN] => EC-8JH22470WY0704826
    [TIMESTAMP] => 2015-08-11T17:24:08Z
    [CORRELATIONID] => 18a347794c5a1
    [ACK] => Success
    [VERSION] => 78
    [BUILD] => 000000
)

好的,我找到了一个网站,在那里我可以创建必要的沙盒帐户:https://developer.paypal.com/docs/classic/lifecycle/sb_create-accounts/