All function now implemented

parent 5212edb5
...@@ -106,7 +106,7 @@ class Client ...@@ -106,7 +106,7 @@ class Client
$result = curl_exec($ch); $result = curl_exec($ch);
if (curl_errno($ch)) { if (curl_errno($ch)) {
throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: ", var_export(curl_getinfo($ch), true)); throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true));
} }
if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) { if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) {
// πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής" // πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής"
...@@ -129,7 +129,7 @@ class Client ...@@ -129,7 +129,7 @@ class Client
$result = curl_exec($ch); $result = curl_exec($ch);
if (curl_errno($ch)) { if (curl_errno($ch)) {
throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: ", var_export(curl_getinfo($ch), true)); throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true));
} }
if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) { if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) {
// πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής" // πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής"
...@@ -156,7 +156,7 @@ class Client ...@@ -156,7 +156,7 @@ class Client
$result = curl_exec($ch); $result = curl_exec($ch);
if (curl_errno($ch)) { if (curl_errno($ch)) {
throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: ", var_export(curl_getinfo($ch), true)); throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true));
} }
if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) { if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) {
// πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής" // πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής"
......
...@@ -21,31 +21,25 @@ http://generic.local.dev/public/pdf/Q%2BnehDdzn91TSuVrWOWtoQ%3D%3D/eyJhbGciOiJIU ...@@ -21,31 +21,25 @@ http://generic.local.dev/public/pdf/Q%2BnehDdzn91TSuVrWOWtoQ%3D%3D/eyJhbGciOiJIU
http://generic.local.dev/public/pdf/download/Q%2BnehDdzn91TSuVrWOWtoQ%3D%3D http://generic.local.dev/public/pdf/download/Q%2BnehDdzn91TSuVrWOWtoQ%3D%3D
Αποστολή αρχείου για πρωτοκόλληση
# Slim Framework 3 Skeleton Application
Use this skeleton application to quickly setup and start working on a new Slim Framework 3 application. This application uses the latest Slim 3 with the PHP-View template renderer. It also uses the Monolog logger. ```sh
#!/bin/sh
This skeleton application was built for Composer. This makes setting up a new Slim Framework application quick and easy. curl -v -X POST \
--header "User-Agent: MINEDU OSTEAM Tester" \
-F "theme=Title" \
-F "mainDoc=@test3-minimal.pdf" \
-F "otherDoc=@test3-minimal.pdf" \
"http://localhost/devel/OpenApi-Papyros-PHP-Clients/slim-app/public/protocol"
```
## Install the Application # Σχετικά με την εφαρμογή
Run this command from the directory in which you want to install your new Slim Framework application. Η εφαρμογή δημιουργήθηκε με σημείο εκκίνησης το Slim Framework 3 Skeleton Application.
Περισσότερες λεπτομέρειες στη [σελίδα του Slim-Skeleton](https://github.com/slimphp/Slim-Skeleton)
php composer.phar create-project slim/slim-skeleton [my-app-name] **Σημαντικό!** Για να τρέξει η εφαρμογή είναι απαραίτητο μετά τη λήψη της
https://github.com/slimphp/Slim-Skeleton να εκτελέσετε την εντολή `composer install` μέσα στο ριζικό της φάκελο
(\slim-app).
Replace `[my-app-name]` with the desired directory name for your new application. You'll want to:
* Point your virtual host document root to your new application's `public/` directory.
* Ensure `logs/` is web writeable.
To run the application in development, you can also run this command.
php composer.phar start
Run this command to run the test suite
php composer.phar test
That's it! Now go build something cool.
...@@ -31,7 +31,7 @@ require __DIR__ . '/../src/middleware.php'; ...@@ -31,7 +31,7 @@ require __DIR__ . '/../src/middleware.php';
// setup the app // setup the app
// //
$container['autoloader'] = $autoloader; $container['autoloader'] = $autoloader;
$autoloader->addPsr4('Gr\\Gov\\Minedu\\Osteam\\', __DIR__ . '/../src/osteam'); $autoloader->addPsr4('Gr\Gov\Minedu\Osteam\Slim\\', __DIR__ . '/../src/osteam');
$container['errorHandler'] = function ($c) { $container['errorHandler'] = function ($c) {
return function ($request, $response, $exception) use ($c) { return function ($request, $response, $exception) use ($c) {
return $c['response']->withJson([ return $c['response']->withJson([
......
<?php <?php
//
namespace Gr\Gov\Minedu\Osteam; namespace Gr\Gov\Minedu\Osteam\Slim;
use Interop\Container\ContainerInterface; use Interop\Container\ContainerInterface;
use Slim\Http\Body; use Slim\Http\Body;
use Gr\Gov\Minedu\Osteam\Client; use Gr\Gov\Minedu\Osteam\Slim\Client;
/** /**
* Description of app * Description of app
...@@ -35,7 +35,10 @@ class App ...@@ -35,7 +35,10 @@ class App
$this->username = (isset($settings['username']) ? $settings['username'] : ''); $this->username = (isset($settings['username']) ? $settings['username'] : '');
$this->password = (isset($settings['password']) ? $settings['password'] : ''); $this->password = (isset($settings['password']) ? $settings['password'] : '');
$this->sender_id = (isset($settings['sender_id']) ? $settings['sender_id'] : ''); $this->sender_id = (isset($settings['sender_id']) ? $settings['sender_id'] : '');
$this->client = new Client(); $this->client = new Client([
'NO_SAFE_CURL' => (isset($settings['NO_SAFE_CURL']) ? $settings['NO_SAFE_CURL'] : false),
'base_uri' => (isset($settings['base_uri']) ? $settings['base_uri'] : 'https://protocoltest.minedu.gov.gr:443/openpapyros/api')
]);
} }
/** /**
...@@ -66,8 +69,8 @@ class App ...@@ -66,8 +69,8 @@ class App
public function ping($req, $res, $args) public function ping($req, $res, $args)
{ {
return $res->withJson([ return $res->withJson([
'username' => $this->username, 'username' => $this->username,
'sender_id' => $this->sender_id, 'sender_id' => $this->sender_id,
]); ]);
} }
...@@ -155,11 +158,11 @@ class App ...@@ -155,11 +158,11 @@ class App
'docType' => "$doc_type", 'docType' => "$doc_type",
'startDate' => $req->getQueryParam('date_from', date(DATE_W3C, mktime(0, 0, 0, date("m"), date("d") - 5, date("Y")))), 'startDate' => $req->getQueryParam('date_from', date(DATE_W3C, mktime(0, 0, 0, date("m"), date("d") - 5, date("Y")))),
'endDate' => $req->getQueryParam('date_to', date(DATE_W3C)), 'endDate' => $req->getQueryParam('date_to', date(DATE_W3C)),
] ]
); );
return $res->withJson([ return $res->withJson([
'hashIds' => json_decode($this->client->searchDocuments($payload, $apikey)) 'hashIds' => json_decode($this->client->searchDocuments($payload, $apikey))
]); ]);
} }
...@@ -197,62 +200,55 @@ class App ...@@ -197,62 +200,55 @@ class App
$res = $res->withBody(new Body(fopen('php://temp', 'r+'))); $res = $res->withBody(new Body(fopen('php://temp', 'r+')));
$res->getBody()->write(base64_decode($result["document"]["base64"])); $res->getBody()->write(base64_decode($result["document"]["base64"]));
return $res return $res
->withHeader('Content-Description', 'Get file ' . filter_var($result["description"], FILTER_SANITIZE_STRING)) ->withHeader('Content-Description', 'Get file ' . filter_var($result["description"], FILTER_SANITIZE_STRING))
->withHeader('Content-Type', 'application/pdf') ->withHeader('Content-Type', 'application/pdf')
->withHeader('Content-Disposition', 'attachment;filename="' . basename($result["fileName"]) . '"') ->withHeader('Content-Disposition', 'attachment;filename="' . basename($result["fileName"]) . '"')
->withHeader('Content-Transfer-Encoding', 'binary') ->withHeader('Content-Transfer-Encoding', 'binary')
->withHeader('Expires', '0') ->withHeader('Expires', '0')
->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') ->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->withHeader('Pragma', 'public'); ->withHeader('Pragma', 'public');
} }
///////////////////////////////////////////////////////// public function postProtocol($req, $res, $args)
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
public function postProtocol($submission_data, $apikey = null)
{ {
$postdata = array_merge([ $apikey = (isset($args['apikey']) ? $args['apikey'] : $this->getApiKey());
'senderId' => $this->setting('sender_id'),
], $submission_data $params = $req->getParams();
); $files = $req->getUploadedFiles();
// take care of files... $mainDoc = null;
if (isset($postdata['mainDoc'])) { $attachedDocs = [];
if (is_string($postdata['mainDoc']['document'])) { if (count($files) > 0) {
$postdata['mainDoc']['document'] = $this->_files[$postdata['mainDoc']['document']]; foreach ($files as $id => $file) {
} if ($file->getError() === UPLOAD_ERR_OK) {
} $file_contents = base64_encode($file->getStream()->getContents());
if (isset($postdata['attachedDoc'])) { if ($file_contents !== false) {
$postdata['attachedDoc'] = array_map(function ($doc) { $payload_item = [
if (is_string($doc['document'])) { 'document' => $file_contents,
$doc['document'] = $this->_files[$doc['document']]; 'fileName' => $file->getClientFilename(),
'description' => null
];
if ($id === 'mainDoc') {
$mainDoc = $payload_item;
} else {
$attachedDocs[] = $payload_item;
}
}
} }
return $doc; }
}, $postdata['attachedDoc']);
} }
$payload = json_encode($postdata); $payload_items = [
'senderId' => $req->getParam('sender_id', $this->sender_id),
'theme' => $req->getParam('theme'),
'description' => $req->getParam('description'),
'docCategory' => $req->getParam('docCategory', 20),
'mainDoc' => $mainDoc,
'attachedDoc' => (count($attachedDocs) > 0 ? $attachedDocs : null)
];
$response = json_decode($this->client->postProtocol($payload, $apikey === null ? $this->getApiKey() : $apikey), true); $payload = json_encode($payload_items);
return $response;
}
/** return $this->withJsonReady($res, $this->client->postProtocol($payload, $apikey));
* Read a file to use later
*
* @param string $filename The file to read
* @return boolean
*/
public function loadFile($filename)
{
if (is_readable($filename)) {
$file = base64_encode(file_get_contents($filename));
if ($file !== false) {
$this->_files["$filename"] = $file;
return true;
}
}
return false;
} }
public function setDebug($debug = true) public function setDebug($debug = true)
...@@ -260,4 +256,5 @@ class App ...@@ -260,4 +256,5 @@ class App
$this->client->setDebug($debug === true); $this->client->setDebug($debug === true);
return; return;
} }
} }
<?php <?php
/* /*
* *
*/ */
namespace Gr\Gov\Minedu\Osteam;
namespace Gr\Gov\Minedu\Osteam\Slim;
use Exception; use Exception;
...@@ -29,7 +31,7 @@ class Client ...@@ -29,7 +31,7 @@ class Client
$result = $this->put("{$this->_settings['base_uri']}/pauthenticate/pauth", $payload, [ $result = $this->put("{$this->_settings['base_uri']}/pauthenticate/pauth", $payload, [
"Content-Type: application/json", "Content-Type: application/json",
"Accept: application/json", "Accept: application/json",
] ]
); );
return $result; return $result;
} }
...@@ -40,7 +42,7 @@ class Client ...@@ -40,7 +42,7 @@ class Client
"api_key: {$apikey}", "api_key: {$apikey}",
"Content-Type: application/json", "Content-Type: application/json",
"Accept: application/json", "Accept: application/json",
] ]
); );
return $result; return $result;
} }
...@@ -51,7 +53,7 @@ class Client ...@@ -51,7 +53,7 @@ class Client
"api_key: {$apikey}", "api_key: {$apikey}",
"Content-Type: text/plain", "Content-Type: text/plain",
"Accept: application/json", "Accept: application/json",
] ]
); );
return $result; return $result;
} }
...@@ -62,7 +64,7 @@ class Client ...@@ -62,7 +64,7 @@ class Client
"api_key: {$apikey}", "api_key: {$apikey}",
"Content-Type: text/plain", "Content-Type: text/plain",
"Accept: application/json", "Accept: application/json",
] ]
); );
return $result; return $result;
} }
...@@ -73,7 +75,7 @@ class Client ...@@ -73,7 +75,7 @@ class Client
"api_key: {$apikey}", "api_key: {$apikey}",
"Content-Type: application/json", "Content-Type: application/json",
"Accept: application/json", "Accept: application/json",
] ]
); );
return $result; return $result;
} }
...@@ -83,6 +85,9 @@ class Client ...@@ -83,6 +85,9 @@ class Client
curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, "OSTEAM barebone php client"); curl_setopt($ch, CURLOPT_USERAGENT, "OSTEAM barebone php client");
if (isset($this->_settings['NO_SAFE_CURL']) && $this->_settings['NO_SAFE_CURL'] === true) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3); curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
...@@ -109,7 +114,7 @@ class Client ...@@ -109,7 +114,7 @@ class Client
throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true)); throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true));
} }
// if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) { // if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) {
// πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής" // πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής"
// throw new Exception("Αποτυχημένη κλήση. HTTP STATUS {$http_code}. Η απάντηση ήταν: {$result}", $http_code); // throw new Exception("Αποτυχημένη κλήση. HTTP STATUS {$http_code}. Η απάντηση ήταν: {$result}", $http_code);
// } // }
curl_close($ch); curl_close($ch);
...@@ -132,7 +137,7 @@ class Client ...@@ -132,7 +137,7 @@ class Client
throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: ", var_export(curl_getinfo($ch), true)); throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: ", var_export(curl_getinfo($ch), true));
} }
// if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) { // if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) {
// πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής" // πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής"
// throw new Exception("Αποτυχημένη κλήση. HTTP STATUS {$http_code}. Η απάντηση ήταν: {$result}", $http_code); // throw new Exception("Αποτυχημένη κλήση. HTTP STATUS {$http_code}. Η απάντηση ήταν: {$result}", $http_code);
// } // }
curl_close($ch); curl_close($ch);
...@@ -159,7 +164,7 @@ class Client ...@@ -159,7 +164,7 @@ class Client
throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: ", var_export(curl_getinfo($ch), true)); throw new Exception("Λάθος κατά την κλήση του {$uri}. Curl error: " . curl_error($ch) . " Curl info: ", var_export(curl_getinfo($ch), true));
} }
// if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) { // if (intval(($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) / 100) != 2) {
// πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής" // πραγματοποιήθηκε κλήση αλλά δεν ήταν "επιτυχής"
// throw new Exception("Αποτυχημένη κλήση. HTTP STATUS {$http_code}. Η απάντηση ήταν: {$result}", $http_code); // throw new Exception("Αποτυχημένη κλήση. HTTP STATUS {$http_code}. Η απάντηση ήταν: {$result}", $http_code);
// } // }
curl_close($ch); curl_close($ch);
...@@ -171,4 +176,5 @@ class Client ...@@ -171,4 +176,5 @@ class Client
$this->_debug = ($debug === true); $this->_debug = ($debug === true);
return; return;
} }
} }
<?php <?php
$app->get('/ping', '\Gr\Gov\Minedu\Osteam\App:ping');
$app->get('/apikey', '\Gr\Gov\Minedu\Osteam\App:apiKey'); $app->get('/ping', '\Gr\Gov\Minedu\Osteam\Slim\App:ping');
$app->get('/docdata/{hashid}[/{apikey}]', '\Gr\Gov\Minedu\Osteam\App:docData'); $app->get('/apikey', '\Gr\Gov\Minedu\Osteam\Slim\App:apiKey');
$app->get('/search[/{doc_type}]', '\Gr\Gov\Minedu\Osteam\App:searchDocuments'); $app->get('/docdata/{hashid}[/{apikey}]', '\Gr\Gov\Minedu\Osteam\Slim\App:docData');
$app->get('/pdf/download/{hashid}[/{apikey}]', '\Gr\Gov\Minedu\Osteam\App:pdfDownload'); $app->get('/search[/{doc_type}]', '\Gr\Gov\Minedu\Osteam\Slim\App:searchDocuments');
$app->get('/pdf/{hashid}[/{apikey}]', '\Gr\Gov\Minedu\Osteam\App:pdfData'); $app->get('/pdf/download/{hashid}[/{apikey}]', '\Gr\Gov\Minedu\Osteam\Slim\App:pdfDownload');
$app->get('/pdf/{hashid}[/{apikey}]', '\Gr\Gov\Minedu\Osteam\Slim\App:pdfData');
$app->post('/protocol[/{apikey}]', '\Gr\Gov\Minedu\Osteam\Slim\App:postProtocol');
$app->any('/[{anythingelse}]', function ($request, $response, $args) { $app->any('/[{anythingelse}]', function ($request, $response, $args) {
$this->logger->info("Void response, no action route was enabled"); $this->logger->info("Void response, no action route was enabled");
return $response->withJson([ return $response->withJson([
'message' => 'Δεν αναγνωρίστηκε το αίτημα σας', 'message' => 'Δεν αναγνωρίστηκε το αίτημα σας',
'in' => var_export($args, true) 'in' => var_export($args, true)
], 404 ], 404
); );
}); });
...@@ -20,6 +20,7 @@ return [ ...@@ -20,6 +20,7 @@ return [
'username' => 'test', 'username' => 'test',
'password' => '123456', 'password' => '123456',
// sender id for test lookups // sender id for test lookups
'sender_id' => 100000001 'sender_id' => 100000001,
'NO_SAFE_CURL' => false
], ],
]; ];
#!/bin/sh
curl -v -X POST \
--header "User-Agent: MINEDU OSTEAM Tester" \
-F "theme=Title" \
-F "mainDoc=@test3-minimal.pdf" \
-F "otherDoc=@test3-minimal.pdf" \
"http://localhost/devel/OpenApi-Papyros-PHP-Clients/slim-app/public/protocol"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment