get_variable('URA', true); $idFatura = $agi->get_variable('IDFATURA', true); $emailCliente = $agi->get_variable('EMAIL', true); $telefoneCliente = $agi->get_variable('TELCLIENTE', true); if ($opcao == 1) { $res = EnviaBoletosEmail($idFatura, $emailCliente); if ($res == 'success') { $agi->exec_goto(GetAnuncio('FATURA_ENVIADA_FIBNET')); } else { $agi->exec_goto(GetAnuncio('ENVIO_FATURA_FALHA_FIBNET')); } } elseif ($opcao == 2) { $res = EnviaBoletosSms($idFatura,$telefoneCliente); if ($res == 'success') { $agi->exec_goto(GetAnuncio('FATURA_ENVIADA_FIBNET')); } else { $agi->exec_goto(GetAnuncio('ENVIO_FATURA_FALHA_FIBNET')); } } else { $agi->exec_goto(GetFila('ATENDIMENTO_FIBNET')); } } catch (Exception $ex) { $reg_msg = $ex->getMessage(); $reg_status_exec = 'Er'; __logStr("Envia Boletos", $reg_msg . "Envio de Boletos", $script, true); } @AtualizaIntegracao($uid, $reg_retorno, $reg_msg, $reg_status_exec, $retorno_cliente); if(!$dadosIntegra)@grava_dadosIntegra($reg_retorno); function EnviaBoletosEmail($idFatura, $emailAdd = null) { $clientId = "5"; $clientSecret = "B7fuHYQykrCYmtWkz7YgDcybwUk509PiF8u99oBp"; $username = "api@simplesip.com.br"; $password = "!@#simplesip_api_fibnet!@#"; if (!empty($idFatura)) { $requestBody = array( "client_id" => $clientId, "client_secret" => $clientSecret, "username" => $username, "password" => $password, "grant_type" => "password" ); try { $req = curl_init("https://api.fibnet.hubsoft.com.br/oauth/token"); $header = array(); $header[] = 'Accept: application/json'; curl_setopt($req, CURLOPT_HTTPHEADER, $header); curl_setopt($req, CURLOPT_RETURNTRANSFER, true); curl_setopt($req, CURLOPT_POST, true); curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($requestBody)); $resp = json_decode(curl_exec($req), true); curl_close($req); } catch (Exception $ex) { $msg = $ex->getMessage(); return $msg; } } try { $tokenType = $resp['token_type']; $accessToken = $resp['access_token']; $authorizationToken = $tokenType . " " . $accessToken; $postfields = array( "id_fatura" => $idFatura, "email_adicional" => [ $emailAdd ] ); $req = curl_init("https://api.fibnet.hubsoft.com.br/api/v1/integracao/cliente/financeiro/enviar_email"); $header = array(); $header[] = 'Accept: application/json'; if (!is_null($authorizationToken)) { $header[] = 'Authorization: ' . $authorizationToken; } curl_setopt($req, CURLOPT_HTTPHEADER, $header); curl_setopt($req, CURLOPT_RETURNTRANSFER, true); curl_setopt($req, CURLOPT_POST, true); curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($postfields)); $result = json_decode(curl_exec($req), true); curl_close($req); $cliente = objectToArray($result); if ($cliente['status'] == 'error') { return array($cliente['msg'], $cliente['errors']); } else { return $cliente['status']; } } catch (Exception $ex) { $msg = $ex->getMessage(); return $msg; } } function EnviaBoletosSms($idFatura, $telAdd = null) { $clientId = "5"; $clientSecret = "B7fuHYQykrCYmtWkz7YgDcybwUk509PiF8u99oBp"; $username = "api@simplesip.com.br"; $password = "!@#simplesip_api_fibnet!@#"; if (!empty($idFatura)) { $requestBody = array( "client_id" => $clientId, "client_secret" => $clientSecret, "username" => $username, "password" => $password, "grant_type" => "password" ); try { $req = curl_init("https://api.fibnet.hubsoft.com.br/oauth/token"); $header = array(); $header[] = 'Accept: application/json'; curl_setopt($req, CURLOPT_HTTPHEADER, $header); curl_setopt($req, CURLOPT_RETURNTRANSFER, true); curl_setopt($req, CURLOPT_POST, true); curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($requestBody)); $resp = json_decode(curl_exec($req), true); curl_close($req); } catch (Exception $ex) { $msg = $ex->getMessage(); return $msg; } } try { $tokenType = $resp['token_type']; $accessToken = $resp['access_token']; $authorizationToken = $tokenType . " " . $accessToken; $postfields = array( "id_fatura" => $idFatura, "telefone_adicional" => [ $telAdd ] ); $req = curl_init("https://api.fibnet.hubsoft.com.br/api/v1/integracao/cliente/financeiro/enviar_sms"); $header = array(); $header[] = 'Accept: application/json'; if (!is_null($authorizationToken)) { $header[] = 'Authorization: ' . $authorizationToken; } curl_setopt($req, CURLOPT_HTTPHEADER, $header); curl_setopt($req, CURLOPT_RETURNTRANSFER, true); curl_setopt($req, CURLOPT_POST, true); curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($postfields)); $result = json_decode(curl_exec($req), true); curl_close($req); $cliente = objectToArray($result); if ($cliente['status'] == 'error') { return array($cliente['msg'], $cliente['errors']); } else { return $cliente['status']; } } catch (Exception $ex) { $msg = $ex->getMessage(); return $msg; } } function objectToArray($d) { if (is_object($d)) { $d = get_object_vars($d); } if (is_array($d)) { return array_map(__FUNCTION__, $d); } else { return $d; } }