在进行API调用期间出现cURL错误。 cURL错误号:[60] SSL证书概率:证书链中的自签名证书

时间:2017-08-03 00:22:49

标签: php laravel ssl curl quickbooks-online

美好的一天,我是服务器设置的新手。我目前正在使用laravel 5.4将我的quickbooks app集成到我的实时服务器http://qb.dagnum.com/connect上,但我仍然会收到此错误

(1/1) SdkException
cURL error during making API call. cURL Error Number:[60] with error:[SSL certificate problem: self signed certificate in certificate chain]

我使用' composer需要quickbooks / v3-php-sdk'添加了包。服务器已通过SSL认证已安装,但我仍然收到错误。

我的代码:

use App\Http\Controllers\Controller;   
use QuickBooksOnline\API\DataService\DataService;

class Auth2Controller extends Controller
 {
  public function index()
   {

        $dataService = DataService::Configure(array(
         'auth_mode' => 'oauth2',
         'ClientID' => "Q0lCkcEshsGMHOEula2r5RKc2yhxvMsYEpKN1lw1WZwyfd1Si6",
         'ClientSecret' => "gE0F9hLgwx9OBzRpNxyOvWJH6L2fIhzAwBugPJHq",
         'accessTokenKey' => 'eyJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiYWxnIjoiZGlyIn0..4z4Assj4x1qt8H4DtQco6A.nmV2jTxaDMVdFWEUO16q5qhbd5aD6U-U-RYnSNywqg-HPC_3_jvwpMJU1a1S5X-PgPUy60WvVy_8p1awY7kIoFzTV4IhdFLrZpYtBUGCjcsvjxWeOSgP6oCayBEmCv7zzabtgB6vxU46jQqKX2IXYUGPPtyYO64hrgELFR4SKUK6boZiVnh8z19gnvsReKMmIINA3-NgC6QJqMRp6HWgzCa9RuDN9tCtrAK2dy5xmJRNSNgdv_gyg1bfdX4l4b30fLPzFk31fsTT9NTJq9PuGtdTsvUuCj7Hme6HPldD9TKYRXWU8TKrQQrQWEpdlbPr6F3rhP6IdmCv9t1XH_WzF_1IseRUoYhiTUjubig-j8gzwajIdYQTzpJQKJ92QiAEyt8k40WWg0v69hEC0w7WRBuUE-IJ50xWypqS_P28IWt1G14rovZ97soGOteSik-41g1icR2zxfNhXGq7zO7oU5B8r-ej5Pb52T0MCMktgd6y32bqwo2pcEzblL2bZs7DZ7LDx5peY4TIfGW21crTE6xjhRr7LdqB8K505pRqIOP20eaRgwtGHLZ3bdBt1_negw2AGjc409BM0nLzzmODxr3yo-YdGwkcOjm5QgbGAsrnpoSo9tSpxPHoN0vMRneRdsKCd6CZG5M1OIOMuj7spkm442tvwiAMCx2Fh-STG6fMnhOq7l_f8NW_3kscxtF2.obQxJKjPfi1KlaQQ_OUoNg',
         'refreshTokenKey' => "L011509163184Q0K7DT40SVXhJXAfyoj6B6EbSr3Ty64yVvF5A",
         'QBORealmID' => "123145857569084",
         'baseUrl' => "https://sandbox-quickbooks.api.intuit.com"
      ));

      $dataService->setMinorVersion("9");
      $CompanyInfo = $dataService->getCompanyInfo();
      $error = $dataService->getLastError();

    if ($error != null) {
        echo "The Status code is: " . $error->getHttpStatusCode() . "\n";
        echo "The Helper message is: " . $error->getOAuthHelperError() . "\n";
        echo "The Response message is: " . $error->getResponseBody() . "\n";
        echo "The Intuit Helper message is: IntuitErrorType:{" . $error->getIntuitErrorType() . "} IntuitErrorCode:{" . $error->getIntuitErrorCode() . "} IntuitErrorMessage:{" . $error->getIntuitErrorMessage() . "} IntuitErrorDetail:{" . $error->getIntuitErrorDetail() . "}";
    } 

   }

我也看到了卷曲功能

private function setSSL(&$curl_opt, $verifySSL){
      if($verifySSL){
          $curl_opt[CURLOPT_SSL_VERIFYPEER] = true;
          $curl_opt[CURLOPT_SSL_VERIFYHOST] = 2;
          $curl_opt[CURLOPT_CAINFO] = dirname(dirname(__FILE__)) . "/OAuth/OAuth2/certs/apiintuitcom.pem"; //Pem certification Key Path
     }
    }

试图替换

$curl_opt[CURLOPT_CAINFO] = dirname(dirname(__FILE__)) . "/OAuth/OAuth2/certs/apiintuitcom.pem";

to `$curl_opt[CURLOPT_CAINFO] ="/home/servername/public_html/quickbooks_app/resources/cert/cacert.pem";` 

但是我收到了这个错误     Http状态代码:[401] Http Response Body为null或Empty。

我该怎么做才能解决这个问题..

2 个答案:

答案 0 :(得分:1)

我删除了SDK附带的apiintuitcom.pem文件,并开始使用PHP_OAuth2.0示例应用中可以找到的cacert.pem。我也使用了错误的 baseUrl ,但我改变了你的。这为我解决了这个问题。我的setSSL方法现在看起来像这样:

private function setSSL(&$curl_opt, $verifySSL){
  if($verifySSL){
      $curl_opt[CURLOPT_SSL_VERIFYPEER] = true;
      $curl_opt[CURLOPT_SSL_VERIFYHOST] = 2;
      $curl_opt[CURLOPT_CAINFO] = dirname(dirname(__FILE__)) . "/OAuth/OAuth2/certs/cacert.pem"; //Pem certification Key Path
  }
}

我的$dataService几乎和你的一样。

答案 1 :(得分:0)

你去/ vendor / quickbooks / v3-php-sdk / src / Core / HttpClients并编辑CurlHttpClient.php

找到

// $curl_opt[CURLOPT_CAINFO] = dirname(dirname(__FILE__)) . "/OAuth/OAuth2/certs/apiintuitcom.pem"; //Pem certification Key Path

将其更改为

' $curl_opt[CURLOPT_CAINFO] ="/home/folder/public_html/quickbooks_app/resources/cert/cacert.pem"; 

注意:您可以将cacert.pem放在任何位置,只需更改链接它的地址即可。

您可以在此网站https://curl.haxx.se/docs/caextract.html

上获取cacert.pem