返回参数:
"error":"invalid_client","error_description":"The client credentials are invalid"}"
模式
贝宝支付分为两种模式:
沙盒模式(sandbox)
和正式(live)
,出现401问题基本就是账户和模式不匹配问题。代码内设置模式如下:
$this->PayPal->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
)
);
$this->PayPal->setConfig(
array(
'mode' => 'live',
'log.LogEnabled' => true,
'log.FileName' => '../PayPal.log',
'log.LogLevel' => 'FINE', // PLEASE USE FINE LEVEL FOR LOGGING IN LIVE ENVIRONMENTS
'cache.enabled' => true,
// 'http.CURLOPT_CONNECTTIMEOUT' => 30
// 'http.headers.PayPal-Partner-Attribution-Id' => '123123123'
)
);
命令查询
通过命令行直接先测试下账号问题:
curl -v -u "AV-SNw2j-1wNqAb1ygg0I4iKT8E8zHT1QCh8eLEbeFZQN2slHhq4dX5pKn4mfz7CHGDhCaVX1NhShB0G:EHjumNJEwf5lkurMyNqo1DJ1v64jsZ9mpFYlKIkVQBh6Kksygxx_u77F8G0rSQHW9Awezdqd4RCdGmVM" "https://api.sandbox.paypal.com/v1/oauth2/token" -X POST -d "response_type=token&grant_type=client_credentials"
curl -v -u "client_id:secret" "https://api.sandbox.paypal.com/v1/oauth2/token" -X POST -d "response_type=token&grant_type=client_credentials"
-u 用户名:密码登录
-v, --verbose Make the operation more talkative
-d data
成功返回:
{
"scope": "https://uri.paypal.com/services/invoicing https://uri.paypal.com/services/disputes/read-buyer https://uri.paypal.com/services/payments/realtimepayment https://uri.paypal.com/services/disputes/update-seller https://uri.paypal.com/services/payments/payment/authcapture openid https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/payments/refund https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/payments/.* https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.* https://uri.paypal.com/services/subscriptions https://uri.paypal.com/services/applications/webhooks",
"access_token": "A21AALPwFtDpb5jpWRVv_VvX3aiGGGRQag6qJUOT6tLfPpalV2pTkGY4I_KUbJjuxNCg1XA7XyiFinMBZuYMEYhDbfxgcQrwg",
"token_type": "Bearer",
"app_id": "APP-80W284485P519543I",
"expires_in": 31035,
"nonce": "2020-12-11T03:23:27ZQMW1i1Gnu2BtxvJ5V_EJBwN1dRMeFd3Ujp61jYMODlY"
}