php5.2 curl 問題

最近發現在一些老舊的windows程式中(php5.2),使用財政部發票api的時候, 突然出現錯誤訊息

CURLOPT_SSL_VERIFYPEER false 14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

然而實際上 已經關閉ssl的驗證機制了,但是還是依然出現這項錯誤。

function fnToolsPost($aQuery){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($ch, CURLOPT_URL, 'https://api.einvoice.nat.gov.tw/PB2CAPIVAN/invServ/InvServ');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aQuery)  );

    $temp1=curl_exec($ch);

    if( $temp1 === false ){
        echo 'Curl ERROR: ' . curl_error($ch);

        return $temp1;
    }else{
        return $temp1;
    }
}

離奇的事,在linux and php7 的情況下是可以運作的。

解決辦法

將windows中php7 的 libeay32.dll,ssleay32.dll 取代 php5.2 中的相同檔案。 即可解決。

「Laravel」Laravel Debugbar

Install use Composer

# composer require barryvdh/laravel-debugbar --dev
composer require barryvdh/laravel-debugbar:^2.3 --dev

P.S.You can find information in composer.json

set service provider AppServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {

        // ===== THIS IS Register LARAVEL DEBUGBAR 
        if ($this->app->environment() == 'local')
        {
            $this->app->register('Barryvdh\Debugbar\ServiceProvider');
        }
        //==========================

    }
}

set Facade config/app.php:

    'aliases' => [

        ...............        

        // Laravel Debugbar
        'Debugbar' => Barryvdh\Debugbar\Facade::class,

    ],

];

check .env


APP_ENV=local
APP_DEBUG=true

參考

  1. https://my.oschina.net/u/2400083/blog/988715

「Laravel」 composer

install composer

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

instasll laravel


composer create-project --prefer-dist laravel/laravel PROJECT