PHP - SSL certificate error: unable to get local issuer certificate

https://stackoverflow.com/questions/28858351/php-ssl-certificate-error-unable-to-get-local-issuer-certificate

第一个问题 ✔

 
Finally got this to work!

Download the certificate bundle.

Put it somewhere. In my case, that was c:\wamp\ directory (if you are using Wamp 64 bit then it's c:\wamp64\).

Enable mod_ssl in Apache and php_openssl.dll in php.ini (uncomment them by removing ; at the beginning). But be careful, my problem was that I had two php.ini files and I need to do this in both of them. One is the one you get from your WAMP taskbar icon, and another one is, in my case, in C:\wamp\bin\php\php5.5.12\

Add these lines to your cert in both php.ini files:

curl.cainfo="C:/wamp/cacert.pem"
openssl.cafile="C:/wamp/cacert.pem"
Restart Wamp services.

第二个问题 ✔

Disclaimer: This code makes your server insecure.

I had the same problem in Mandrill.php file after line number 65 where it says $this->ch = curl_init();

Add following two lines:

curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
This solved my problem and also sent email using localhost but I suggest to NOT use it on live version live. On your live server the code should work without this code.

 

 https://stackoverflow.com/questions/8227909/curl-exec-always-returns-false

我的最终代码

//获取openid

    public function doPageOpenid(){
        global $_W, $_GPC;
        $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));

        //声明CODE,获取小程序传过来的CODE
        $code = $_GPC['code'];
        //配置appid
        $appid = $res['appid'];
        //配置appscret
        $secret = $secret=$res['appsecret'];
        //api接口
        $api = "https://api.weixin.qq.com/sns/jscode2session?appid=".$appid."&secret=".$secret."&js_code=".$code."&grant_type=authorization_code";
        //获取GET请求
        function httpGet($url){
            try {
                $ch = curl_init();

                if (FALSE === $ch)
                    throw new Exception('failed to initialize');

                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_TIMEOUT, 500);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                curl_setopt($ch, CURLOPT_URL, $url);
                $content = curl_exec($ch);

                if (FALSE === $content){
                    $err1111=curl_error($ch);
                    $err2222=curl_errno($ch);
                
                    throw new Exception(curl_error($ch), curl_errno($ch));
                }
                // ...process $content now
                return $content;
            } catch(Exception $e) {

                trigger_error(sprintf(
                'Curl failed with error #%d: %s',
                $e->getCode(), $e->getMessage()),
                E_USER_ERROR);

            }
        }
        //发送
        $str = httpGet($api);
        print_r($str);
    }

 

posted @ 2018-10-06 16:21  德丽莎·阿波卡利斯  阅读(316)  评论(0编辑  收藏  举报