<?php 
session_start(); 
require_once('../conexion.php');
require_once('../include/sesiones.php');
require_once('../php_api/api.php');

$api_contrasena=$_POST["api_contrasena"]; 
$nameimagen = $_FILES['certi']['name'];
$convert = file_get_contents($_FILES['certi']['tmp_name']);
$api_base64 = base64_encode($convert);

$json = array(
    "certificate" => $api_base64,
    "password" => $api_contrasena
);

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "{$configuration->base_url}ubl2.1/config/certificate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS =>json_encode($json),

CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'cache-control: no-cache',
    'Connection: keep-alive',
    'Accept-Encoding: gzip, deflate',
    'Host: localhost',
    'accept: application/json',
    'X-CSRF-TOKEN: ',
    'Authorization: Bearer '.$token
  ),
));

$response = curl_exec($curl);
curl_close($curl);
$data = json_decode($response, true);
$mensaje       = $data['message'];
$certificado = $data['certificado'];
$fechaExpira   = $certificado['expiration_date'];

$sql=mysqli_query($con,"UPDATE configuracion_electronica Set ele_fecha_certificado='$fechaExpira' Where empresa='$empresa'") or die(mysqli_error($con)); 

echo '<div class="alert alert-success alert-dismissable">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
        <strong>' .$mensaje.'</strong> 
    </div>'; 
?>