2016-10-21 3 views
0

私の国の支払いプラットフォームのmailwizzで支払いゲートウェイを開発しようとしていました。その後、支払いゲートウェイのクラスを使用してトランザクションを確認するために、私はエラーを得た... HERESに私はこの問題は、支払いゲートウェイのクラス内から来ていると思うどこカールが暗号化された接続を確立しようとしますが、ない場合に発生curlがレスポンスで失敗しました: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; 


} 
+2

他の読者には、明確な問題文がない質問は役に立ちません。参照:最小、完全、および検証可能なサンプル(http://stackoverflow.com/help/mcve)の作成方法 –

+0

[curl:(60)SSL証明書:ローカル発行者証明書を取得できません](http: /stackoverflow.com/questions/24611640/curl-60-ssl-certificate-unable-to-get-local-issuer-certificate) – Clay

答えて

1

どの証明書が信頼できるかを判断するために必要なローカル証明書ストアを持っている。

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

か、そのすべてのようにCAINFOphp.ini内を設定します。

カールがローカル証明書ストアを見つけるために、どこ知っているように設定を追加します。

は、2つのオプションがありますcURL操作では、毎回そのオプションを設定する必要はなく、同じ証明書ファイルを使用します。

php.iniの

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

は、私はFirefoxの内部の証明書ストアの鏡であると考えてthis pem fileを、使用していました。また、参照してくださいthis answer

+0

回答ありがとうございました。試してみてください。うまくいけば教えてください – carrion

+0

私はこれを試しましたそれは働いている証明書を使って私のドメインのです...しかし、SSLチェックを無効にするには、 – carrion

+1

@carrionをテストするためにsslをチェックせずに動作させる方法があります。 'curl_setopt($ ch、CURLOPT_SSL_VERIFYPEER、false);' – BeetleJuice

関連する問題