Paypal在调用刷新令牌后返回“400无法刷新访问令牌”

时间:2017-05-16 11:26:15

标签: php paypal

我使用Paypal SDK来授权我的网站上的客户端,但是当我尝试获取access_token时,Paypal会返回400错误,其描述为“无法刷新访问令牌”。

默认示例正在运行。

请帮忙,因为我无法前进。

我的代码列表:

use PayPal\Api\OpenIdTokeninfo;
use PayPal\Api\OpenIdUserinfo;

$refreshToken = 'C21AAHGeO4Ah7vrYzFNmvCxn9wplulKX-TIe17wfWDRIXMPH4MBIRkMN5OCuFUk-QcKBsTD3MWRX3j3tQ4xVcMHLh5pmIl42A';
$clientId = 'AZGKPdDCkeDGNgkje2b__yIWZBUWiDfEifiGJwoiD4ksmCDD4FieN_oW2a82yjcKCyeubAfO2uQZsUwP';
$clientSecret = 'EGwnYPLfXB8NSXCIeJho23kPw9hXxWiP22LaP8gmFjPDL5XX3TGFpEUn1m4ascle7727pX5fWEHAy5V9';
$apiContext = new \PayPal\Rest\ApiContext(
        new \PayPal\Auth\OAuthTokenCredential(
            $clientId,
            $clientSecret
        )
    );

    $apiContext->setConfig(
        array(
            'mode' => 'sandbox',
            'log.LogEnabled' => true,
            'log.FileName' => 'PayPal.log',
            'log.LogLevel' => 'DEBUG', // PLEASE USE `INFO` LEVEL FOR LOGGING IN LIVE ENVIRONMENTS
            'cache.enabled' => true,
            // 'http.CURLOPT_CONNECTTIMEOUT' => 30
            // 'http.headers.PayPal-Partner-Attribution-Id' => '123123123'
            //'log.AdapterFactory' => '\PayPal\Log\DefaultLogFactory' // Factory class implementing \PayPal\Log\PayPalLogFactory
        )
    );
try {
        $tokenInfo = new OpenIdTokeninfo();
        $tokenInfo = $tokenInfo->createFromRefreshToken(array('refresh_token' => $refreshToken), $apiContext);

        $params = array('access_token' => $tokenInfo->getAccessToken());
        $userInfo = OpenIdUserinfo::getUserinfo($params, $apiContext);
} catch (Exception $ex) {
        // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
        var_dump("User Information", "User Info", null, $params, $ex);
        exit(1);
}

var_dump("User Information", "User Info", $userInfo->getUserId(), $params, $userInfo);

代码执行的结果:

>

 string(16) "User Information"
string(9) "User Info"
NULL
NULL
object(PayPal\Exception\PayPalConnectionException)#23 (9) {
["url":"PayPal\Exception\PayPalConnectionException":private]=>
string(69) "https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice"
["data":"PayPal\Exception\PayPalConnectionException":private]=>
string(180) "{"error_description":"Unable to refresh access token","error":"invalid_request","correlation_id":"c4532fe46a761","information_link":""}"
["message":protected]=>
string(112) "Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice."
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(400)
["file":protected]=>
string(91) "/var/www/melony/app/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php"
["line":protected]=>
int(154)
["trace":"Exception":private]=>
array(4) {
[0]=>
array(6) {
["file"]=>
string(90) "/var/www/melony/app/vendor/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php"
["line"]=>
int(73)
["function"]=>
string(7) "execute"
["class"]=>
string(32) "PayPal\Core\PayPalHttpConnection"
["type"]=>
string(2) "->"
["args"]=>
array(1) {
[0]=>
string(136) "refresh_token=C21AAHGeO4Ah7vrYzFNmvCxn9wplulKX-TIe17wfWDRIXMPH4MBIRkMN5OCuFUk-QcKBsTD3MWRX3j3tQ4xVcMHLh5pmIl42A&grant_type=refresh_token"
}
}
[1]=>
array(6) {
["file"]=>
string(92) "/var/www/melony/app/vendor/paypal/rest-api-sdk-php/lib/PayPal/Common/PayPalResourceModel.php"
["line"]=>
int(102)
["function"]=>
string(7) "execute"
["class"]=>
string(31) "PayPal\Transport\PayPalRestCall"
["type"]=>
string(2) "->"
["args"]=>
array(5) {
[0]=>
array(1) {
[0]=>
string(26) "PayPal\Handler\RestHandler"
}
[1]=>
string(39) "/v1/identity/openidconnect/tokenservice"
[2]=>
string(4) "POST"
[3]=>
string(136) "refresh_token=C21AAHGeO4Ah7vrYzFNmvCxn9wplulKX-TIe17wfWDRIXMPH4MBIRkMN5OCuFUk-QcKBsTD3MWRX3j3tQ4xVcMHLh5pmIl42A&grant_type=refresh_token"
[4]=>
array(2) {
["Content-Type"]=>
string(33) "application/x-www-form-urlencoded"
["Authorization"]=>
string(222) "Basic QVpHS1BkRENrZURHTmdramUyYl9feUlXWkJVV2lEZkVpZmlHSndvaUQ0a3NtQ0RENEZpZU5fb1cyYTgyeWpjS0N5ZXViQWZPMnVRWnNVd1A6RUd3bllQTGZYQjhOU1hDSWVKaG8yM2tQdzloWHhXaVAyMkxhUDhnbUZqUERMNVhYM1RHRnBFVW4xbTRhc2NsZTc3MjdwWDVmV0VIQXk1Vjk="
}
}
}
[2]=>
array(6) {
["file"]=>
string(85) "/var/www/melony/app/vendor/paypal/rest-api-sdk-php/lib/PayPal/Api/OpenIdTokeninfo.php"
["line"]=>
int(248)
["function"]=>
string(11) "executeCall"
["class"]=>
string(33) "PayPal\Common\PayPalResourceModel"
["type"]=>
string(2) "::"
["args"]=>
array(5) {
[0]=>
string(39) "/v1/identity/openidconnect/tokenservice"
[1]=>
string(4) "POST"
[2]=>
string(136) "refresh_token=C21AAHGeO4Ah7vrYzFNmvCxn9wplulKX-TIe17wfWDRIXMPH4MBIRkMN5OCuFUk-QcKBsTD3MWRX3j3tQ4xVcMHLh5pmIl42A&grant_type=refresh_token"
[3]=>
array(2) {
["Content-Type"]=>
string(33) "application/x-www-form-urlencoded"
["Authorization"]=>
string(222) "Basic QVpHS1BkRENrZURHTmdramUyYl9feUlXWkJVV2lEZkVpZmlHSndvaUQ0a3NtQ0RENEZpZU5fb1cyYTgyeWpjS0N5ZXViQWZPMnVRWnNVd1A6RUd3bllQTGZYQjhOU1hDSWVKaG8yM2tQdzloWHhXaVAyMkxhUDhnbUZqUERMNVhYM1RHRnBFVW4xbTRhc2NsZTc3MjdwWDVmV0VIQXk1Vjk="
}
[4]=>
object(PayPal\Rest\ApiContext)#11 (2) {
["requestId":"PayPal\Rest\ApiContext":private]=>
NULL
["credential":"PayPal\Rest\ApiContext":private]=>
object(PayPal\Auth\OAuthTokenCredential)#12 (7) {
["clientId":"PayPal\Auth\OAuthTokenCredential":private]=>
string(80) "AZGKPdDCkeDGNgkje2b__yIWZBUWiDfEifiGJwoiD4ksmCDD4FieN_oW2a82yjcKCyeubAfO2uQZsUwP"
["clientSecret":"PayPal\Auth\OAuthTokenCredential":private]=>
string(80) "EGwnYPLfXB8NSXCIeJho23kPw9hXxWiP22LaP8gmFjPDL5XX3TGFpEUn1m4ascle7727pX5fWEHAy5V9"
["accessToken":"PayPal\Auth\OAuthTokenCredential":private]=>
NULL
["tokenExpiresIn":"PayPal\Auth\OAuthTokenCredential":private]=>
NULL
["tokenCreateTime":"PayPal\Auth\OAuthTokenCredential":private]=>
NULL
["cipher":"PayPal\Auth\OAuthTokenCredential":private]=>
object(PayPal\Security\Cipher)#13 (1) {
["secretKey":"PayPal\Security\Cipher":private]=>
string(80) "EGwnYPLfXB8NSXCIeJho23kPw9hXxWiP22LaP8gmFjPDL5XX3TGFpEUn1m4ascle7727pX5fWEHAy5V9"
}
["_propMap":"PayPal\Common\PayPalModel":private]=>
array(0) {
}
}
}
}
}
[3]=>
array(6) {
["file"]=>
string(35) "/var/www/melony/app/test/paypal.php"
["line"]=>
int(146)
["function"]=>
string(22) "createFromRefreshToken"
["class"]=>
string(26) "PayPal\Api\OpenIdTokeninfo"
["type"]=>
string(2) "->"
["args"]=>
array(2) {
[0]=>
array(1) {
["refresh_token"]=>
string(97) "C21AAHGeO4Ah7vrYzFNmvCxn9wplulKX-TIe17wfWDRIXMPH4MBIRkMN5OCuFUk-QcKBsTD3MWRX3j3tQ4xVcMHLh5pmIl42A"
}
[1]=>
object(PayPal\Rest\ApiContext)#11 (2) {
["requestId":"PayPal\Rest\ApiContext":private]=>
NULL
["credential":"PayPal\Rest\ApiContext":private]=>
object(PayPal\Auth\OAuthTokenCredential)#12 (7) {
["clientId":"PayPal\Auth\OAuthTokenCredential":private]=>
string(80) "AZGKPdDCkeDGNgkje2b__yIWZBUWiDfEifiGJwoiD4ksmCDD4FieN_oW2a82yjcKCyeubAfO2uQZsUwP"
["clientSecret":"PayPal\Auth\OAuthTokenCredential":private]=>
string(80) "EGwnYPLfXB8NSXCIeJho23kPw9hXxWiP22LaP8gmFjPDL5XX3TGFpEUn1m4ascle7727pX5fWEHAy5V9"
["accessToken":"PayPal\Auth\OAuthTokenCredential":private]=>
NULL
["tokenExpiresIn":"PayPal\Auth\OAuthTokenCredential":private]=>
NULL
["tokenCreateTime":"PayPal\Auth\OAuthTokenCredential":private]=>
NULL
["cipher":"PayPal\Auth\OAuthTokenCredential":private]=>
object(PayPal\Security\Cipher)#13 (1) {
["secretKey":"PayPal\Security\Cipher":private]=>
string(80) "EGwnYPLfXB8NSXCIeJho23kPw9hXxWiP22LaP8gmFjPDL5XX3TGFpEUn1m4ascle7727pX5fWEHAy5V9"
}
["_propMap":"PayPal\Common\PayPalModel":private]=>
array(0) {
}
}
}
}
}
}
["previous":"Exception":private]=>
NULL
}

0 个答案:

没有答案