Hallo,
danke für die Info, hab ich mir angeschaut. Hat mir aber nicht geholfen, es scheinte ein größeres Problem zu sein.
Ich habe ein Testserver auf dem hat mein php script ohne Probleme funktioniert. Nur auf dem Livesystem nicht. Ich habe dann gedacht es muss ja dann an der OTRS Installation liegen. Dann habe ich vom Livesystem die Dateien zum Testsystem rüberkopiert und die selbe Datenbank verbunden. Und das Testsystem ging immer noch ohne Probleme, dann habe ich beschlossen das es an irgendetwas größerem liegen muss und das System neu installiert. Beim direktaufruf mit dem Browser der URL hat sich die Antwort schon unterschieden- Beim Aufruf von http://otrs_url.de/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector/ auf dem Testsystem bekam ich "Length Required" als Antwort und beim Livesystem direkt einen Fehler: "Fehler 324 (net::ERR_EMPTY_RESPONSE): Server hat die Verbindung geschlossen. Es wurden keine Daten gesendet."
Jetzt habe ich ein kleines neues Problem. Ich kann pro OTRS Verbindung immer nur eine Funktion ausführen. Wenn ich die zweite aufrufe bekomme ich den selben Fehler mit den Headers wie oben.
Wenn ich am Anfang von jeder Funktion ein connect und am Ende ein disconnect mache dann funktioniert das (siehe code). Das ist aber ja sicher nicht so gewollt.
Ich habe hier mal eine php Datei zusammengestellt die bei euch so sofort funktionieren sollte.
Code: Select all
<?php
class client_otrs
{
var $otrs;
var $url;
var $wslogin_user;
var $wslogin_pass;
var $user_queue;
var $user_pass;
var $session;
private $arr_soap_client;
function __construct()
{
$this->user_queue = "OTRS_USER";
$this->user_pass = "OTRS_PW";
$this->url = "http://OTRS_URL/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector/";
$this->arr_soap_client = array(
'location' => $this->url,
'uri' => "Core",
'connection_timeout' => 5,
'trace' => 1,
'exceptions' => 1,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED
);
$this->otrs = new SoapClient(null, $this->arr_soap_client) or die("faild to create Object");
}
function connect()
{
try
{
$this->otrs = new SoapClient(null, $this->arr_soap_client) or die("faild to create Object");
}
catch (SoapFault $e)
{
$this->test();
//throw new SoapFault("OTRS-01","ERROR! SOAP RESPONSE: ".$e->getMessage());
}
}
function disconnect()
{
unset($this->otrs);
}
function CreateSession()
{
$this->connect();
try
{
$param_array = array(
new SoapParam($this->user_queue, 'UserLogin'),
new SoapParam($this->user_pass, 'Password')
);
$this->session = $this->otrs->__soapCall('SessionCreate', $param_array);
}
catch (SoapFault $e)
{
$this->test();
//throw new SoapFault("OTRS-02","ERROR! SOAP RESPONSE: ".$e->getMessage());
}
$this->disconnect();
}
function __destruct()
{
$this->disconnect();
}
function TicketSearch($subject,$body)
{
$this->connect();
try
{
$param_array = array(
new SoapParam($this->session, 'SessionID'),
//new SoapParam($this->user_queue, 'UserLogin'),
//new SoapParam($this->user_pass, 'Password'),
new SoapParam($subject,'Subject'),
new SoapParam($body, 'Body')
);
$TicketSearch = $this->otrs->__soapCall('TicketSearch', $param_array);
error_log("TicketSearch: ".json_encode($TicketSearch));
return $TicketSearch;
}
catch (SoapFault $e)
{
$this->test();
//throw new SoapFault("OTRS-03","ERROR! SOAP RESPONSE: ".json_encode($e));
}
$this->disconnect();
}
function CreateTicket($arr_attr_ticket="",$arr_attr_article="")
{
$this->connect();
try
{
$param_array = array(
//new SoapParam($this->user_queue, 'UserLogin'),
//new SoapParam($this->user_pass, 'Password'),
new SoapParam($this->session, 'SessionID'),
);
if ($arr_attr_ticket!="")
{
$param_array[] = new SoapParam($arr_attr_ticket,'Ticket');
}
if ($arr_attr_article!="")
{
$param_array[] = new SoapParam($arr_attr_article,'Article');
}
$TicketID = $this->otrs->__soapCall('TicketCreate', $param_array);
return $TicketID;
}
catch (SoapFault $e)
{
$this->test();
//throw new SoapFault("OTRS-04","ERROR! SOAP RESPONSE: ".json_encode($e)); //$e->getMessage());
}
$this->disconnect();
}
function UpdateTicket($ticketID,$arr_attr_ticket="",$arr_attr_article="")
{
$this->connect();
try
{
$param_array = array(
//new SoapParam($this->user_queue, 'UserLogin'),
//new SoapParam($this->user_pass, 'Password'),
new SoapParam($this->session, 'SessionID'),
new SoapParam($ticketID,'TicketID')
);
if ($arr_attr_ticket!="")
{
$param_array[] = new SoapParam($arr_attr_ticket,'Ticket');
}
if ($arr_attr_article!="")
{
$param_array[] = new SoapParam($arr_attr_article,'Article');
}
//return $param_array;
$TicketID = $this->otrs->__soapCall('TicketCreate', $param_array);
return $TicketID;
}
catch (SoapFault $e)
{
$this->test();
//throw new SoapFault("OTRS-04","ERROR! SOAP RESPONSE: ".$e->getMessage());
}
$this->disconnect();
}
function get_ticket($ticketnumber)
{
$this->connect();
try
{
//$this->session="102a78fe03d9cb54618b004495894651d6";
$param_array = array(
//new SoapParam($this->user_queue, "UserLogin"),
//new SoapParam($this->user_pass, "Password"),
new SoapParam($this->session, 'SessionID'),
new SoapParam($ticketnumber, 'TicketID')
);
/*$param_array = array(
//new SoapParam($this->user, "UserLogin"),
//new SoapParam($this->pass, "Password"),
'SessionID'=>$this->session,
'TicketID'=>$ticketnumber
);
*/
$getTicket = $this->otrs->__soapCall('TicketGet', $param_array);
return $getTicket;
}
catch (SoapFault $e)
{
$this->test();
//throw new SoapFault("OTRS-05","ERROR! SOAP RESPONSE: ".$e->getMessage());
}
$this->disconnect();
}
function test()
{
echo "<hr>getLastRequestHeaders: ";
print_r(htmlentities($this->otrs->__getLastRequestHeaders()));
echo "<hr>getLastRequest: ";
print_r(htmlentities($this->otrs->__getLastRequest()));
echo "<hr>";
echo "<hr>getLastResponseHeaders: ";
print_r(htmlentities($this->otrs->__getLastResponseHeaders()));
echo "<hr>getLastResponse: ";
print_r(htmlentities($this->otrs->__getLastResponse()));
}
public function otrs($subject, $body, $customerFrom, $customerID, $queue, $articleType)
{
$otrs = new client_otrs();
$otrs->CreateSession();
$Ticket_nr=$otrs->TicketSearch($subject, $body);
$arr_ticket=array(
"StateID"=>'1',
"Title"=>$subject,
"Queue"=>$queue,
"CustomerUser"=>$customerFrom,
"CustomerID"=>$customerID,
"PriorityID"=>3
);
$arr_article=array(
"Subject"=>$subject,
"Body"=>$body,
"ContentType" => 'text/plain; charset=utf8',
"ArticleType" => $articleType
);
echo json_encode($Ticket_nr);
if ($Ticket_nr!="")
{
$ticket=$otrs->get_ticket($Ticket_nr);
print_r($ticket);
if ($ticket->StateID!='1' and $ticket->StateID!='4')
{
$arr_ticket["StateID"]='2';
$arr_article["Subject"]="Open";
$arr_article["Body"]="Webservice-OTRS-Ticket wurde erneut geöffnet";
$arr_article["ArticleType"]="SendAgentNotification";
$arr_article["HistoryType"]="AddNote";
echo json_encode($otrs->UpdateTicket($Ticket_nr,$arr_ticket,$arr_article));
}
}
else
{
echo json_encode($otrs->CreateTicket($arr_ticket,$arr_article));
}
}
}
// $subject, $body, $customerFrom, $customerID, $queue, $ArticleType
$otrs = new client_otrs();
echo $otrs->otrs("Hallo Welt2", "Hier ist das erste Testticket", "customerFrom", "customerID", "queue","email-external");
?>
Als weitere Frage, ich möchte an Personen ein Ticket schicken, die noch kein Kunde bei OTRS sind. Das Problem ist nur das ich zu dem Zeitpunkt den Vor und Nachnamen nicht im System habe. Da ich die User Persönlich ansprechen möchte, würde ich diese gerne übergeben. Hat dazu jemand eine Idee?
Dankeschön im Vorraus
