From bbfa3270e9fa2f14d7aa01d79f1feafaf9e8d36c Mon Sep 17 00:00:00 2001 From: Stavros Papadakis <spapad@gmail.com> Date: Fri, 23 Dec 2016 10:51:18 +0200 Subject: [PATCH] Post protocol function --- base-php-client/index.php | 44 ++++++++++++++++++++++++++++++++++ base-php-client/src/App.php | 15 ++++++++++-- base-php-client/src/Client.php | 11 +++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/base-php-client/index.php b/base-php-client/index.php index d7364b2..00a750f 100644 --- a/base-php-client/index.php +++ b/base-php-client/index.php @@ -82,6 +82,50 @@ try { exit(-1); } +/** + * ΞΟΞΏΟΟΞΏΞ»Ξ� Ξ±ΟΟΞ΅Ξ―ΞΏΟ Ξ³ΞΉΞ± ΟΟΟΟΞΏΞΊΟλληΟΞ· + */ +if ($send) { + echo "ΞΟΞΏΟΟΞΏΞ»Ξ� ΡγγΟΞ¬ΟΞΏΟ ...", PHP_EOL; + echo "ΞλΡγΟΞΏΟ Ξ³ΞΉΞ± ΟΞΏ Ξ±ΟΟΡίο {$options['send']}... "; + if (is_readable($options['send'])) { + $file = base64_encode(file_get_contents($options['send'])); + if ($file === false) { + echo PHP_EOL, "ΞΞΞΞΞ£: ΞΞ΄Ο Ξ½Ξ±ΞΌΞ―Ξ± ΞΊΟδικοΟΞΏΞ―Ξ·ΟΞ·Ο ΟΞΏΟ Ξ±ΟΟΞ΅Ξ―ΞΏΟ .", PHP_EOL; + } + echo "OK", PHP_EOL; + } else { + echo PHP_EOL, "ΞΞΞΞΞ£: ΀ο Ξ±ΟΟΡίο δΡν Ρίναι Ξ±Ξ½Ξ±Ξ³Ξ½ΟΟΞΉΞΌΞΏ.", PHP_EOL; + exit(-1); + } + + try { + // ΞΊΞ±ΞΈΞΏΟΞΉΟΞΌΟΟ ΟΞ±ΟΞ±ΞΌΞΟΟΟΞ½ ΟΞ΅ ΟΞ―Ξ½Ξ±ΞΊΞ± Ξ³ΞΉΞ± Ξ±ΟλοΟΞΏΞ―Ξ·ΟΞ· + $submission_data = [ + 'theme' => 'ΞΞΞΞΞΞ: ΞΟ ΟΞΏΞΌΞ±ΟΞΏΟΞΏΞΉΞ·ΞΌΞΞ½ΞΏ κΡίμΡνο ΟΞ·Ο ' . date('c'), + 'description' => 'ΞΞΞΞΞΞ: ΞΟ ΟΞΏΞΌΞ±ΟΞΏΟΞΏΞΉΞ·ΞΌΞΞ½ΞΏ κΡίμΡνο ΟΞ΅ΟΞΉΞ³ΟΞ±ΟΞ�Ο ' . date('Ymdhmi'), + 'docCategory' => 20, + 'mainDoc' => [ + 'document' => [ + "base64" => $file + ], + 'fileName' => $options['send'], + 'description' => "ΞΞΞΞΞΞ: ΞΟΞΏΟΟΞΏΞ»Ξ� δοκιμαΟΟΞΉΞΊΞΏΟ Ξ±ΟΟΞ΅Ξ―ΞΏΟ {$options['send']}" + ] + // ΟΞΏ ΟΞ±ΟάδΡιγμα δΡν ΟΞ΅ΟιλαμβάνΡι ΟΟ Ξ½Ξ·ΞΌΞΌΞΞ½Ξ± Ξ±ΟΟΡία + // ΞΊΞ±ΞΉ ΞΏΟΞΉΟΞΌΞΞ½Ξ΅Ο Ξ΅ΟΞΉΟΞ»ΞΞΏΞ½ ΟΞ±ΟΞ±ΞΌΞΟΟΞΏΟ Ο + // senderId, senderProtocol, senderProtocolDate, ada, attachedDoc[] + ]; + + $doc_info = $app->postProtocol($submission_data, $apikey); + echo "Ξ Ξ±ΟΞΏΟΟΞΏΞ»Ξ� ολοκληΟΟΞΈΞ·ΞΊΞ΅ ΞΌΞ΅ ΞΞ‘.Ξ .: ", $doc_info["protocolNumber"], PHP_EOL; + echo "ΞΞ½Ξ±Ξ»Ο ΟΞΉΞΊΞ¬: ", print_r($doc_info, true), PHP_EOL; + } catch (\Exception $e) { + echo 'ΞΞΞΞΞ£: ΞΞ΄Ο Ξ½Ξ±ΞΌΞ―Ξ± Ξ±ΟΞΏΟΟΞΏΞ»Ξ�Ο Ξ΅Ξ³Ξ³ΟΞ¬ΟΞΏΟ . ', PHP_EOL, $e->getMessage(), PHP_EOL; + exit(1); + } +} + /** * ΞΡιΟΞΏΟ ΟΞ³Ξ―Ξ± Ξ»Ξ�ΟΞ·Ο Ξ»Ξ―ΟΟΞ±Ο ΟΟΞ½ ΞΊΞ±ΟΞ±ΟΟΟΞ·ΞΌΞΞ½ΟΞ½ ΟΟΟΟΞΏΞΊΟλλΟΞ½. * Ξάν ΞΟΡι ΞΆΞ·ΟηθΡί Ξ΅ΟΞΉΟΟΟΞΟΞΏΞ½ΟΞ±ΞΉ ΞΊΞ±ΞΉ ΞΏΞΉ Ξ±Ξ½Ξ±Ξ»Ο ΟΞΉΞΊΞΟ ΟληΟΞΏΟΞΏΟΞ―Ξ΅Ο ΟΟΞ½ ΡγγΟΞ¬ΟΟΞ½. diff --git a/base-php-client/src/App.php b/base-php-client/src/App.php index d94edc2..c9990fa 100644 --- a/base-php-client/src/App.php +++ b/base-php-client/src/App.php @@ -107,9 +107,20 @@ class App return $response; } - public function submit($submission_data, $apikey = null) + public function postProtocol($submission_data, $apikey = null) { - + $payload = json_encode(array_merge([ + 'senderId' => $this->setting('sender_id'), + ], $submission_data + ) + ); + + if ($this->_debug) { + echo "postProtocol :: payload: {$payload}", PHP_EOL; + } + + $response = json_decode($this->client->postProtocol($payload, $apikey === null ? $this->getApiKey() : $apikey), true); + return $response; } public function getPdf($hashid, $apikey = null) diff --git a/base-php-client/src/Client.php b/base-php-client/src/Client.php index b436fe6..e426124 100644 --- a/base-php-client/src/Client.php +++ b/base-php-client/src/Client.php @@ -67,6 +67,17 @@ class Client return $result; } + public function postProtocol($payload, $apikey) + { + $result = $this->post("{$this->_settings['base_uri']}/protocol/submit", $payload, [ + "api_key: {$apikey}", + "Content-Type: application/json", + "Accept: application/json", + ] + ); + return $result; + } + protected function setCommonCurlOptions($ch, $uri, $headers) { curl_setopt($ch, CURLOPT_URL, $uri); -- GitLab