Paypal(PHP):无法使用客户端证书(找不到密钥或错误的密码?)

时间:2015-08-04 05:36:13

标签: php ssl curl paypal

我正在使用Paypal Express Checkout购买我的购物图表。我已经创建了我的API证书文件,如下所示。 enter image description here

我已经下载了api证书文件cert_key_pem.txt并用于api凭证,如下所示。

  $API_UserName = $paypal->username;
  $API_Password = $paypal->password;
  $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
  $PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
  $version="64";
  $currencyCodeType = "USD";
  $paymentType = "Sale";
  $methodName = "DoExpressCheckoutPayment";
  $certFile = 'C:\xampp\htdocs\project-name\cert_key.txt';//forlocalhost
  //$certFile = '/home/cpanel-username/public_html/cert_key_pem.txt'; //for live server

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$API_Endpoint);
  curl_setopt($ch, CURLOPT_VERBOSE, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  curl_setopt($ch, CURLOPT_SSLCERT, $certFile);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_POST, 1);

  $nvpreq="METHOD=" . urlencode($methodName) . "&VERSION=" . urlencode($version) . "&PWD=" . urlencode($API_Password) . "&USER=" . urlencode($API_UserName) . $nvpStr . "&BUTTONSOURCE=" . urlencode($sBNCode);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

 $response = curl_exec($ch);
 if(curl_exec($ch) === false)
  {
     $message = curl_error($ch);
  }
  else
  {
     $message = 'Operation completed without any errors';
  }

 curl_close($ch);

 echo $message;

但我收到如下错误消息。

  unable to use client certificate (no key found or wrong pass phrase?)

如果您对解决此类错误有任何想法,请帮助我。感谢

1 个答案:

答案 0 :(得分:1)

如果您使用证书来验证API,则可能需要将端点更改为https://api.sandbox.paypal.com/nvp

https://api-3t.sandbox.paypal.com/nvp和所有“-3t”加尾端点用于签名auth API调用(3T表示3个令牌:用户名/密码/签名)