<?php
require_once('Agro_Curl.php');

preg_match("/^agrobr-app02\.*/", gethostname(), $matches);

$now = new \Datetime;
try {
    $idAviso = isset($argv[1]) ? $argv[1] : '';
    if (!$idAviso) {
        throw new Exception("Nro. do aviso não informado.");
    }

    if (count($matches)>0) {
        $curl = new Agro_Curl('agronet.agrobrasilseguros.com.br', 'https');
    } else {
        $curl = new Agro_Curl('localhost', 'http');
       // $curl = new Agro_Curl('localhost', 'http');
    }

    $curl->setUrl('/sinistro2/avisosinistro/sendmailaceitacaoaviso');

    $post = array(
        'id_aviso' => $idAviso, 
        'tipo' => isset($argv[2]) ?? $argv[2]
    );

    $curl->doRequest('POST', $post);

    $result = $curl->getResult();
-
    $result = $now->format('Y-m-d H:i:s') . ": ".$result->message." \n";
} catch (\Exception $e) {
    $result = $now->format('Y-m-d H:i:s') . ': ' . $e->getMessage() . '. ' . $e->getTraceAsString() ."\n";
}