249 lines
No EOL
9.1 KiB
PHP
249 lines
No EOL
9.1 KiB
PHP
<?php
|
|
namespace App\Services;
|
|
|
|
use GuzzleHttp\Client;
|
|
use Storage;
|
|
|
|
class Passolution
|
|
{
|
|
|
|
private $aid;
|
|
private $apw;
|
|
private $sid;
|
|
private $sidpw;
|
|
private $lang;
|
|
private $nat;
|
|
private $destco;
|
|
private $tdat;
|
|
private $descd;
|
|
private $trv;
|
|
private $ino;
|
|
private $vis;
|
|
private $enr;
|
|
private $agency;
|
|
|
|
private $htmlText = "";
|
|
private $pdfPath = [];
|
|
|
|
private $pdf_dir = "";
|
|
private $pdf_path = "";
|
|
private $pdf_name = "";
|
|
|
|
public $additionalContent = "";
|
|
|
|
public function __construct($data = [])
|
|
{
|
|
//User-ID of the travel agency to which the data is forwarded
|
|
$this->aid = "sterntours@passolution.de";
|
|
//User password of the travel agency to which the data is forwarded
|
|
$this->apw = "JfSRv!vJXa";
|
|
//User-ID of the enquirer
|
|
$this->sid = "sterntours@passolution.de";
|
|
//User-Password of the enquirer
|
|
$this->sidpw = "JfSRv!vJXa";
|
|
//Enrichment of the data by country details
|
|
$this->descd = 0;
|
|
//Enrichment of the data by infomation on transit visa
|
|
$this->trv = 1;
|
|
//Enrichment of the data by vaccination regulations
|
|
$this->ino = 1;
|
|
//Enrichment of the data by visa requirements
|
|
$this->vis = 1;
|
|
//Transaction key external system
|
|
$this->enr = 123123;
|
|
//Agency number of the travel agency to which the data is forwarded
|
|
$this->agency = 1000;
|
|
|
|
$this->pdf_dir = 'pdf/passolution/';
|
|
|
|
$this->fill($data);
|
|
|
|
}
|
|
|
|
public function fill($data = []){
|
|
|
|
//Language in which the data is desired
|
|
$this->lang = isset($data['lang']) ? $data['lang'] : 'de';
|
|
//Nationality of the traveller
|
|
$this->nat = isset($data['nat']) ? $data['nat'] : 'de';
|
|
//Country-Code of the destination
|
|
$this->destco = isset($data['destco']) ? $data['destco'] : 'de';
|
|
//Travel dates in format DD-MM-YYYY
|
|
$this->tdat = isset($data['tdat']) ? $data['tdat'] : date("d-m-Y");
|
|
|
|
}
|
|
|
|
public function read($create = false, $return = true)
|
|
{
|
|
|
|
$url = "https://api01.passolution.de/condition/search.php";
|
|
$url .= "?aid=".$this->aid;
|
|
$url .= "&apw=".$this->apw;
|
|
$url .= "&sid=".$this->sid;
|
|
$url .= "&sidpw=".$this->sidpw;
|
|
$url .= "&lang=".$this->lang;
|
|
$url .= "&nat=".$this->nat;
|
|
$url .= "&destco=".$this->destco;
|
|
$url .= "&tdat=".$this->tdat;
|
|
$url .= "&descd=".$this->descd;
|
|
$url .= "&trv=".$this->trv;
|
|
$url .= "&ino=".$this->ino;
|
|
$url .= "&vis=".$this->vis;
|
|
$url .= "&enr=".$this->enr;
|
|
$url .= "&agency=".$this->agency;
|
|
|
|
$client = new Client();
|
|
$res = $client->get($url, [
|
|
]);
|
|
|
|
if($res->getStatusCode() == 200){
|
|
$body = $res->getBody();
|
|
$body = json_decode($body);
|
|
|
|
if($body == null){
|
|
return '';
|
|
}
|
|
if(isset($body->status) && $body->status !== 200){
|
|
return isset($body->message) ? $body->message : '';
|
|
}
|
|
$this->htmlText = "";
|
|
if(is_array($body->response)){
|
|
foreach ($body->response as $response){
|
|
$this->htmlText .= "<p><strong>".$response->additionalContent."</strong></p>";
|
|
$this->additionalContent = trim(substr($response->additionalContent, (strpos($response->additionalContent, "/")+1)));
|
|
|
|
$this->htmlText .= "<h2>".$response->entry->response->headline."</h2>";
|
|
$this->htmlText .= "<p>".$response->entry->response->content."</p>";
|
|
|
|
$this->htmlText .= "<h2>".$response->visa->response->headline."</h2>";
|
|
$this->htmlText .= "<p>".$response->visa->response->content."</p>";
|
|
|
|
$this->htmlText .= "<h2>".$response->transitvisa->response->headline."</h2>";
|
|
$this->htmlText .= "<p>".$response->transitvisa->response->content."</p>";
|
|
|
|
$this->htmlText .= "<h2>".$response->inoculation->response->headline."</h2>";
|
|
$this->htmlText .= "<p>".$response->inoculation->response->content."</p>";
|
|
}
|
|
}else{
|
|
$this->htmlText .= "<p><strong>".$body->response->additionalContent."</strong></p>";
|
|
$this->additionalContent = trim(substr($body->response->additionalContent, (strpos($body->response->additionalContent, "/") +1)));
|
|
|
|
$this->htmlText .= "<h2>".$body->response->entry->headline."</h2>";
|
|
$this->htmlText .= "<p>".$body->response->entry->content."</p>";
|
|
|
|
$this->htmlText .= "<h2>".$body->response->visa->headline."</h2>";
|
|
$this->htmlText .= "<p>".$body->response->visa->content."</p>";
|
|
|
|
$this->htmlText .= "<h2>".$body->response->transitvisa->headline."</h2>";
|
|
$this->htmlText .= "<p>".$body->response->transitvisa->content."</p>";
|
|
|
|
$this->htmlText .= "<h2>".$body->response->inoculation->headline."</h2>";
|
|
$this->htmlText .= "<p>".$body->response->inoculation->content."</p>";
|
|
}
|
|
|
|
if($create){
|
|
$this->createPDF();
|
|
}
|
|
return nl2br($this->htmlText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function createPDF(){
|
|
|
|
$this->createPDFName();
|
|
$this->storagePath();
|
|
|
|
$this->onlyCreatePDF();
|
|
|
|
$this->pdfPath = [
|
|
'filename' => $this->pdf_name,
|
|
'disk' => Storage::disk('public')->path( $this->pdf_dir.$this->pdf_name ),
|
|
'url' => Storage::disk('public')->url($this->pdf_dir.$this->pdf_name)
|
|
];
|
|
return $this->pdfPath;
|
|
}
|
|
|
|
public function onlyCreatePDF(){
|
|
$pdf_file = new CreatePDF('pdf.passolution');
|
|
$pdf_file->create(['contents' => $this->htmlText], $this->pdf_name, 'save', $this->pdf_path.$this->pdf_dir);
|
|
}
|
|
|
|
public function findOrCreatePDF($create = false, $resync = false){
|
|
|
|
$this->createPDFName();
|
|
$this->storagePath();
|
|
$bool = Storage::disk('public')->exists( $this->pdf_dir.$this->pdf_name );
|
|
if(!$bool && $create || $resync){
|
|
$this->read();
|
|
$this->onlyCreatePDF();
|
|
$bool = true;
|
|
}
|
|
|
|
if($bool){
|
|
$this->pdfPath = [
|
|
'filename' => $this->pdf_name,
|
|
'disk' => Storage::disk('public')->path( $this->pdf_dir.$this->pdf_name ),
|
|
'url' => Storage::disk('public')->url($this->pdf_dir.$this->pdf_name),
|
|
'size' => Storage::disk('public')->size($this->pdf_dir.$this->pdf_name),
|
|
'date' => Storage::disk('public')->lastModified($this->pdf_dir.$this->pdf_name),
|
|
];
|
|
}
|
|
|
|
return $this->pdfPath;
|
|
}
|
|
|
|
public function getPdfPath($key = null){
|
|
if($key !== null && is_array($key)){
|
|
$ret = [];
|
|
foreach ($key as $k){
|
|
if(isset($this->pdfPath[$k])){
|
|
$ret[$k] = $this->pdfPath[$k];
|
|
}
|
|
}
|
|
return $ret;
|
|
}
|
|
if($key !== null && isset($this->pdfPath[$key])){
|
|
return $this->pdfPath[$key];
|
|
}
|
|
|
|
return $this->pdfPath;
|
|
}
|
|
|
|
public function createPDFName(){
|
|
$this->pdf_name = "Einreisebestimmungen_".$this->lang."_".$this->nat."-".$this->destco.".pdf";
|
|
}
|
|
|
|
public function storagePath(){
|
|
|
|
if(!Storage::disk('public')->exists( $this->pdf_dir )){
|
|
Storage::disk('public')->makeDirectory($this->pdf_dir); //creates directory
|
|
}
|
|
$this->pdf_path = Storage::disk('public')->getAdapter()->getPathPrefix();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* https://api01.passolution.de/condition/search.php?aid=cliquers@passolution.de&apw=Yuyjf8Mi3x&nat=de&destco=eg&descd=0&trv=1&ino=1&vis=1&tdat=20-12-2018&enr=123123&agency=1000&sid=10001&sidpw=dhfZD3f*/
|
|
|
|
|
|
/*
|
|
*
|
|
* aid Nutzer-ID des Reisebüros, an das die Daten weiter geleitet werden ja 10010
|
|
apw Nutzer-Passwort des Reisebüros, an das die Daten weiter geleitet werden ja dhHz42w
|
|
lang Sprache, in der der Inhalt angefordert wird nein de,en,…
|
|
nat Nationalität des Reisenden (mehrfachabfrage ist möglich) ja de,ch,at,…
|
|
dest3l 3-Letter-Code des Reiseziels dest3l oder destco pmi,hrg,…
|
|
destco Ländercode des Reiseziels (mehrfachabfrage ist möglich) dest3l oder destco eg,es,…
|
|
tdat Reisedatum im Format TT-MM-YYYY nein 21-12-2020
|
|
enr Vorgangsnummer externes System nein A123433
|
|
agency Agentur Nummer des Reisebüros, an das die Daten weiter geleitet werden nein A123433
|
|
sid Nutzer-ID des Anfragenden ja 10010
|
|
sidpw Nutzer-Passwort des Anfragenden ja dhHz42w
|
|
ino Anreichern der Daten um die Impfvorschriften nein 0 oder 1
|
|
descd Anreichern der Daten um Länderdetails nein 0 oder 1
|
|
trv Anreichern der Daten um Informationen zum Transitvisum nein 0 oder 1
|
|
vis Anreichern der Daten um Visabestimmungen nein 0 oder 1
|
|
ck Prüft in Verbindung mit tdat, enr, desto und nat, ob zwischen der ersten und der aktuellen Anfrage mitteilungsrelevante Änderungen statt gefunden haben. Das Ergebnis wird in der JSON Antwort unter importantchanges im Bereich condition, inoculation und visa angezeigt. nein 0 oder 1
|
|
*/ |