【问题标题】:Using certificate for PayPal API with PHP cURL使用 PHP cURL 的 PayPal API 证书
【发布时间】:2013-07-24 16:56:25
【问题描述】:

我正在为 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)

我做错了什么?

【问题讨论】:

    标签: php curl paypal certificate


    【解决方案1】:

    变化:

    curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "\cert_key_pem.txt");
    

    收件人:

    curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . "\cert_key_pem.txt");
    

    并确保网络服务器可以读取证书文件。

    注意:因为它涉及您的 API 凭证的一部分,所以我建议将文件放在您的 webroot 之外(因为您现在似乎没有这样做)。

    【讨论】:

    • 效果很好。谢谢!我想知道您是否知道我们是否可以在沙盒环境中使用证书?我的开发者门户中的沙盒帐户只有 API 凭据中的签名。
    • 是的,我刚刚将证书文件保存在 webroot 中,因为我只是在测试是否使用证书得到响应。我现在要改变它的位置。
    • 您也可以在 Sandbox 中使用 API 证书,是的。但是您需要先删除 API 签名,然后才能申请 API 证书;您不能同时使用两者,这就是您现在看不到该选项的原因。
    猜你喜欢
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 2014-04-27
    • 2012-12-30
    • 1970-01-01
    • 2011-10-31
    • 2013-03-21
    相关资源
    最近更新 更多