[英]Using certificate for PayPal API with PHP cURL
我正在使用PayPal的RefundTransaction API。 虽然我使用签名没有困难,但是我不知道如何使用证书。 我从网站(.txt)下载了证书,并获得了用户名和密码。 我正在使用以下代码:
$this->API_UserName = urlencode("xxx");
$this->API_Password = urlencode("xxx");
$this->API_Signature = urlencode($this->API_Signature);
$this->version = urlencode("104.0");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->API_Endpoint); // https://api.paypal.com/nvp
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "\cert_key_pem.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$reqStr = "METHOD=RefundTransaction&VERSION={$this->version}&PWD={$this->API_Password}&USER={$this->API_UserName}$requestString";
//$requeststring has refund specific fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $reqStr);
// Get response from the server.
$curlResponse = curl_exec($ch);
if(!$curlResponse)
return array("ERROR_MESSAGE"=>"RefundTransaction failed ".curl_error($ch)." (".curl_errno($ch).")");
我收到以下错误:
[ERROR_MESSAGE] => RefundTransaction failedSSL read:
error:00000000:lib(0):func(0):reason(0), errno 0(56)
我究竟做错了什么?
更改:
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "\cert_key_pem.txt");
至:
curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . "\cert_key_pem.txt");
并确保证书文件可被网络服务器读取。
注意:由于它涉及您的API凭证的一部分,因此建议您将文件放置在您的Webroot之外(因为您似乎现在没有这样做)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.