lundi 20 juin 2022

Google Geocoding API error with file_get_contents()

I have a code block that I've cloned from a production environment into a development environment and I'm now getting an error on the dev side that reads:

file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

This is happening on the file_get_contents line below.

I'm unsure why this would not be working now


    $cacheKey = 'postalCodeCoordinates' . $zipcode;
    $coordinates = Cache::get($cacheKey);
    if (is_null($coordinates)) {
        $zipcode = urlencode($zipcode);

        // TODO: replace with way to let user pick country
        $country_component = isset(self::$countryZipOverrides[$zipcode]) ?
                '|country:'.self::$countryZipOverrides[$zipcode]         :
                ''                                                       ;
        $url = "https://maps.googleapis.com/maps/api/geocode/json?components=postal_code:{$zipcode}{$country_component}&sensor=false&key=" . config('services.geocoding.google.key');

        /*error is on this file_get_contents line*/
        $data = file_get_contents($url);
        $json = json_decode($data, true);
        if ($json['results']) {
            $coordinates = $json['results'][0]['geometry']['location'];
            Cache::put(
                $cacheKey,
                $coordinates,
                10080); // 1 week in minutes
            return $coordinates;
        }
    }
    return $coordinates;



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire