Browse Source

foram aplicadas correcoes em alguns metodos utilizados pelo agente, para que sejam retornados no tipo json e identifica a string xml em maiuscula ou minuscula.

correcao_api_simples
douglas.strappasson 1 year ago
parent
commit
af8f2bb188
  1. 40
      integracao/funcoesApi.php

40
integracao/funcoesApi.php

@ -2120,6 +2120,8 @@
global $log, $obsConectaAgente;
$dbcon = $GLOBALS['dbcon'];
$tipoRetorno = $_REQUEST['tipoRetorno'];
try {
if (!isset($_SESSION[SS_NOME_DAC]) || !isset($_SESSION[AGT_MATRICULA]))
throw new Exception("Agente Desconectado!");
@ -2202,9 +2204,8 @@
}
}
$ret = array();
$ret[] = $infoChamada;
return ArrToXml($ret);
$ret = $infoChamada;
return strtoupper($tipoRetorno) != 'XML' ? ResultToJSON($ret, true) : ResultToXml($ret, true);
} catch (Exception $ex) {
@$log[] = $query;
@$log[] = $ex->getMessage();
@ -2854,6 +2855,7 @@
$agtCheck = '';
$result = false;
$_SESSION[SS_AGT_CONTEXTO_RAMAL] = GetContextoRamal($db, $ramal);
$tipoRetorno = $_REQUEST['tipoRetorno'];
if (VerficaAgenteLogado($db)) {
$ramalCon = GetRamalAgenteLogado($db);
@ -2955,7 +2957,7 @@
$ret["tipo_fila"] = $_SESSION[SS_TIPO_FILA];
$ret["message"] = $ultMsg;
}
return ResultToXml($ret);
return strtoupper($tipoRetorno) != 'XML' ? ResultToJSON($ret) : ResultToXml($ret);
}
function RegistraLogin($db, $tipoAtende, $matricula, $ramal, $dacDesc, $login, $dac) {
@ -3173,6 +3175,7 @@
$ramal = GetRamalAgente();
$login = GetLoginAgente();
$dac = GetIdDac();
$tipoRetorno = $_REQUEST['tipoRetorno'];
/*
* Remove o agente da pausa no asterisk.
@ -3185,7 +3188,7 @@
$result = pg_query($db, "begin");
if (!$result) {
$ultMsg = sprintf("Nã foi possível iniciar uma transação com o banco de dados!");
$ultMsg = sprintf("Não foi possível iniciar uma transação com o banco de dados!");
$log[] = $ultMsg;
} else {
@ -3197,7 +3200,7 @@
$result = $result && @pg_affected_rows($result);
if (!$result) {
$ultMsg = sprintf("Nã foi possível atualizar o registro de pausa em \"Eventos Agentes\"!");
$ultMsg = sprintf("Não foi possível atualizar o registro de pausa em \"Eventos Agentes\"!");
$log[] = $ultMsg;
} else {
$query = "update pbx_supervisor_agentes set status = 'LIVRE', duracao = now(), motivo_pausa = '0', status_agente = '0' where matricula = '$matricula'";
@ -3205,7 +3208,7 @@
$result = $result && @pg_affected_rows($result);
if (!$result) {
$ultMsg = sprintf("Nã foi possível atualizar o registro de pausa em \"Supervisor Agentes\"!");
$ultMsg = sprintf("Não foi possível atualizar o registro de pausa em \"Supervisor Agentes\"!");
$log[] = $ultMsg;
}
}
@ -3230,7 +3233,7 @@
$ret["agente_status"] = AGENTE_EM_PAUSA;
$ret["message"] = $ultMsg;
}
return ResultToXml($ret);
return strtoupper($tipoRetorno) != 'XML' ? ResultToJSON($ret) : ResultToXml($ret);
}
@ -3303,6 +3306,8 @@
function DiscarDireto($numeroDiscar, $ramal) {
$db = $GLOBALS['dbcon'];
$tipoRetorno = $_REQUEST['tipoRetorno'];
$result = 1;
$_SESSION[AGT_NUM_DISC] = $numeroDiscar;
@ -3333,7 +3338,7 @@
$ret["result"] = "false";
$ret["message"] = $msgSis;
}
return ResultToXml($ret);
return strtoupper($tipoRetorno) != 'XML' ? ResultToJSON($ret) : ResultToXml($ret);
}
@ -4819,11 +4824,15 @@
return $xml;
}
function ResultToXml($result) {
function ResultToXml($result, $addHeader = false) {
$sessionId = session_id();
$encode = $GLOBALS['encoding'];
$xml = "<?xml version=\"1.0\" encoding=\"$encode\" ?>\n";
$xml .= "<root>\n";
if ($addHeader) {
$xml .= "<status>ok</status>\n";
$xml .= "<SIPID>$sessionId</SIPID>\n";
}
foreach ($result as $key => $value) {
$xml .= sprintf("<%s>%s</%s>\n", $key, $value, $key);
}
@ -4853,12 +4862,19 @@
return stripcslashes($arrAdjust);
}
function ResultToJSON($result) {
function ResultToJSON($result, $addHeader = false) {
$sessionId = session_id();
if ($addHeader) {
$arr = [
"status" => "ok",
"SIPID" => $sessionId,
];
}
foreach ($result as $key => $value) {
$arr[$key] = RemoveAcentos($value);
}
$arr["SPID"] = $sessionId;
return json_encode($arr);
}

Loading…
Cancel
Save