SSL证书问题无法获得本地颁发者证书

Pur*_*ula 5 ssl curl ssl-certificate php-curl

我正在尝试将数据发布到支付网关API.它需要xml格式的发布数据.我有以下代码:

<?php
$requestUrl = 'https://api.given.bypg'; //$block->getPaymentUrl();

$amount = 100; // $block->totalOrderAmount()*100; 

$approveUrl = $block->approveUrl();
$cancelUrl =  $block->cancelUrl();
$declineUrl = $block->declineUrl();


$merchant = 'mydomain.com'; 
//$amount = '100'; // in cents. 1$ = 100cents. 
$currency = '840'; // for dollar
$description = 'Happy customers is what we make.';
$merchantId = 'Nobel106513';
?>

<?php
echo $requestUrl;
$xml_data = '<TKKPG>
<Request>
<Operation>CreateOrder</Operation>
<Language>EN</Language>
<Order>
<OrderType>Purchase</OrderType>
<Merchant>'.$merchantId.'</Merchant>
<Amount>'.$amount.'</Amount>
<Currency>'.$currency.'</Currency>
<Description>'.$description.'</Description>
<ApproveURL>'.$approveUrl.'</ApproveURL>
<CancelURL>'.$cancelUrl.'</CancelURL>
<DeclineURL>'.$declineUrl.'</DeclineURL>
</Order>
</Request>
</TKKPG>';

$ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $requestUrl);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60000);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);//My post data
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_CAPATH, "/etc/apache2/ssl/m4/mydomain.com.crt");
        curl_setopt($ch, CURLOPT_CAINFO, "/etc/apache2/ssl/m4/mydomain.com.crt");
        curl_setopt($ch, CURLOPT_CERTINFO, 1);

        $headers = [];
        array_push($headers, 'Content-Type: text/xml;charset=UTF-8');
        //array_push($headers, 'SoapAction: *');
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $content = trim(curl_exec($ch));
        var_dump($content);
        var_dump(curl_getinfo($ch));
        var_dump(curl_errno($ch));
        var_dump(curl_error($ch));
        curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
  1. 输出 var_dump($content);为空''.
  2. 输出var_dump(curl_getinfo($ch));.

    阵列(大小= 26)
    'URL'=>字符串' 的https://api.given.bypg '
    'CONTENT_TYPE'=>空
    'HTTP_CODE'=> INT 0
    'header_size'=> INT 0
    'request_size'=> 0 INT
    'FILETIME'=> INT -1
    'ssl_verify_result'=> INT 1
    'redirect_count'=> INT 0
    'TOTAL_TIME'=>浮0.488533
    'namelookup_time'=>浮0.028558
    'CONNECT_TIME'=>浮0.256858
    'pretransfer_time'=> 0浮动
    'size_upload'=>浮0
    'size_download'=>浮0
    'speed_download'=>浮0
    'speed_upload'=>浮0
    'download_content_length'=>浮-1
    'upload_content_length'=>浮-1
    'starttransfer_time'=>浮0
    'redirect_time'=>浮0
    'REDIRECT_URL'=>字符串''(长度= 0)
    'primary_ip'=>串'91 .227.244.57' (长度= 13)
    'certinfo'=>
    数组(大小= 0)

    ' primary_port'=> int
    8444'local_ip'=> string'192.168.100.64'(length = 14)
    'local_port'=> int 53456

  3. 输出 var_dump(curl_errno($ch));:int 60

  4. 产量var_dump(curl_error($ch));:

    字符串'SSL证书问题:无法获取本地颁发者证书'(长度= 63) 似乎API没有返回curl_getinfo()上看到的数据.请帮助我,我已经看到社区中建议的几乎所有解决方案.

我已经编辑了我的php.ini文件,以提供从curl网站下载的证书的路径.但这并没有奏效.

Pur*_*ula 0

我得到了 API 提供商的支持,他们指出了我的方法中缺少的东西。对于他们的网关,我需要加载私钥、公钥以及在curl 请求中保护这些密钥的密码。解决方法如下:

/*ssl crts*/
$twpg_cert_file = "/etc/apache2/ssl/m4/mydomain.com.crt";
$twpg_key_file = "/etc/apache2/ssl/m4/mydomain.com.key";
$twpg_key_password = '';
/*ssl crts*/
$ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $requestUrl);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60000);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);//My post data
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_SSLCERT,  $twpg_cert_file);
        curl_setopt($ch, CURLOPT_SSLKEY, $twpg_key_file);
        curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $twpg_key_password);
        curl_setopt($ch, CURLOPT_CERTINFO, 1);
        $headers = [];
        array_push($headers, 'Content-Type: text/xml;charset=UTF-8');
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $content = trim(curl_exec($ch));
        curl_close($ch);
Run Code Online (Sandbox Code Playgroud)

现在一切都按预期进行。