Curl失败,响应:'无法获得本地颁发者证书'mailwizz


Curl failed with response: 'unable to get local issuer certificate' on mailwizz

我一直在尝试在mailwizz上为我的国家开发一个支付平台的支付网关,一切都在工作....这一切都工作,直到我试图验证交易使用支付网关的类,然后我得到了这个错误…这里我认为问题来自于支付网关的类

private function callViaCurl($interface, $payload = [ ], $sentargs = [ ])
{

    $endpoint = PaystackHelpersRouter::PAYSTACK_API_ROOT . $interface[PaystackContractsRouteInterface::ENDPOINT_KEY];
    $method = $interface[PaystackContractsRouteInterface::METHOD_KEY];
    $this->moveArgsToSentargs($interface, $payload, $sentargs);
    $this->putArgsIntoEndpoint($endpoint, $sentargs);
    $headers = ["Authorization"=>"Bearer " . $this->secret_key ];
    $body = '';
    if (($method === PaystackContractsRouteInterface::POST_METHOD)
        || ($method === PaystackContractsRouteInterface::PUT_METHOD)
    ) {
        $headers["Content-Type"] = "application/json";
        $body = json_encode($payload);
    } elseif ($method === PaystackContractsRouteInterface::GET_METHOD) {
        $endpoint = $endpoint . '?' . http_build_query($payload);
    }
    //open connection
    $ch = curl_init();
    // set url
    curl_setopt($ch, CURLOPT_URL, $endpoint);
    if ($method === PaystackContractsRouteInterface::POST_METHOD || $method === PaystackContractsRouteInterface::PUT_METHOD) {
        ($method === PaystackContractsRouteInterface:: POST_METHOD) && curl_setopt($ch, CURLOPT_POST, true);
        ($method === PaystackContractsRouteInterface ::PUT_METHOD) && curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
    }
    //flatten the headers
    $flattened_headers = [];
    while (list($key, $value) = each($headers)) {
        $flattened_headers[] = $key . ": " . $value;
    }
    curl_setopt($ch, CURLOPT_HTTPHEADER, $flattened_headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // Make sure CURL_SSLVERSION_TLSv1_2 is defined as 6
    // Curl must be able to use TLSv1.2 to connect
    // to Paystack servers
    if (!defined('CURL_SSLVERSION_TLSV1_2')) {
        define('CURL_SSLVERSION_TLSV1_2', 6);
    }
    curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSV1_2);
    $response = curl_exec($ch);
    if (curl_errno($ch)) {   // should be 0
        // curl ended with an error
        $cerr = curl_error($ch);
        curl_close($ch);
        throw new Exception("Curl failed with response: '" . $cerr . "'.");
    }
    // Then, after your curl_exec call:
    $resp = json_decode($response);
    //close connection
    curl_close($ch);
    if (!$resp->status) {
        throw new Exception("Paystack Request failed with response: '" . $resp->message . "'.");
    }
    return $resp;

}

当cURL尝试建立加密连接,但没有必要的本地证书存储来确定哪些证书可以信任时,就会发生这种情况。

有两个选项:

1添加一个设置,让cURL知道在哪里找到本地证书存储:

curl_setopt($ch, CURLOPT_CAINFO, '/path/to/cacert.pem');

2或者在php.ini中设置CAINFO,这样所有的cURL操作都将使用相同的证书文件,而不需要每次都设置该选项:

. ini

[curl]
; A default value for CURLOPT_CAINFO option. Must be an absolute path.
curl.cainfo = "/path/to/cacert.pem"

我使用了这个pem文件,我认为它是Firefox内部证书存储的镜像。还可以查看这个答案