/**
  * @param string $operation
  * @param DataPacket $data
  * @param array $files
  *
  * @return string
  */
 public function send($operation, DataPacket $data, $files = [], $decode = true)
 {
     if (!$this->ready()) {
         throw new \RuntimeException('Invalid parameters');
     }
     $data->addRequiredPair('Type', $operation);
     $data->addRequiredPair('terminalID', $this->terminal);
     $data->addRequiredPair('TerminalID', $this->terminal);
     if (!@$data->getRequiredItem('Password')) {
         $data->addRequiredPair('Password', $this->password);
     }
     $data->addRequiredPair('TimePacket', time());
     $data = $data->serializeToString();
     $data = base64_encode($data);
     $data = str_replace(['+', '/'], ['-', '_'], $data);
     $send = [['name' => 'destination', 'contents' => $data], ['name' => 'Hash', 'contents' => md5($data)]];
     if (!empty($files)) {
         foreach ($files as $name => &$file) {
             $send[] = ['name' => $name, 'contents' => $handle = fopen($file, 'r')];
             $file = [$handle, $file];
         }
     }
     $send = new MultipartStream($send);
     $request = new Request('POST', $this->host, ['Content-Type' => 'multipart/form-data; boundary=' . $send->getBoundary()], $send);
     $return = $this->getResponse($request, $decode);
     foreach ($files as $name => $file) {
         fclose($file[0]);
         unlink($file[1]);
     }
     return $return;
 }
Beispiel #2
0
 protected function processRequestTicket(DataPacket $data, &$files)
 {
     /** @var Request $request */
     $request = app(Request::class);
     $input = $request->only(['operator', 'tariff', 'simcard']);
     $ticket = $this->getRandomUUID(false);
     $imagesList = ['list1', 'list2', 'list2_uv', 'list1_uv', 'list3', 'list4', 'photo', 'dogovor'];
     $images = [];
     foreach ($imagesList as $key => $image) {
         if ($request->hasFile($image)) {
             $img = $request->file($image);
             $images[$key + 1 . '.jpg'] = $img->getRealPath();
         }
     }
     if (!empty($images)) {
         $fileName = time() . '_' . $ticket . '.1.zip';
         $zippy = Zippy::load();
         $zippy->create(storage_path('app/' . $fileName), $images);
         $files['uploadfile'] = storage_path('app/' . $fileName);
         $data->addPair('FileTypeParts', 1);
         $data->addPair('FileTotalParts', 1);
         $data->addPair('FileName', $fileName);
         $data->addPair('HashFile', md5_file(storage_path('app/' . $fileName)));
     }
     extract($input, EXTR_OVERWRITE);
     $data->addPair('global_id', $ticket);
     $data->addPair('tarif', $tariff);
     $data->addPair('SimCardCode', $simcard);
     /*
             CountDogovorWasPrinted
             PassportValidation
     */
     app(SessionInterface::class)->set('view.RequestTicket.data', $input);
 }
Beispiel #3
0
 /**
  * Send ticket.
  *
  * @param Request $request
  * @param $server
  * @param $terminal
  */
 public function ticket(TerminalSender $sender, Request $request, $server, $terminal)
 {
     $server = Server::query()->findOrFail($server);
     $terminal = $server->terminals()->findOrFail($terminal);
     $ticket = $this->getRandomUUID(false);
     $imagesList = ['list1', 'list2', 'list2_uv', 'list1_uv', 'list3', 'list4', 'photo', 'dogovor'];
     $images = $files = [];
     foreach ($imagesList as $key => $image) {
         if ($request->hasFile($image)) {
             $img = $request->file($image);
             $images[$key + 1 . '.jpg'] = $img->getRealPath();
         }
     }
     $sender->setCredentials($server->uri, $terminal->guid, $terminal->password);
     $packet = new DataPacket();
     if (!empty($images)) {
         $fileName = time() . '_' . $ticket . '.1.zip';
         $zippy = Zippy::load();
         $zippy->create(storage_path('app/' . $fileName), $images);
         $files['uploadfile'] = storage_path('app/' . $fileName);
         $packet->addPair('FileTypeParts', 1);
         $packet->addPair('FileTotalParts', 1);
         $packet->addPair('FileName', $fileName);
         $packet->addPair('HashFile', md5_file(storage_path('app/' . $fileName)));
     }
     $packet->addPair('global_id', $ticket);
     $packet->addPair('tarif', $request->input('tariff'));
     $packet->addPair('SimCardCode', $request->input('simcard'));
     $packet->addPair('PhoneNumber', '');
     $packet->addPair('PassportValidation', '');
     $result = $sender->send('RequestTicket', $packet, $files);
     /*
             CountDogovorWasPrinted
             PassportValidation
     */
     list($data, $required) = $sender->parseResult($result);
     if (Arr::get($required, 'Result') != 'OK') {
         throw new \RuntimeException();
     }
     $messages = [];
     if ($guid = Arr::get($result, 'global_id')) {
         $messages[] = 'Заявка создана: ' . $guid;
     }
     if ($error = Arr::get($result, 'ErrorMessage')) {
         $messages[] = $error;
     }
     return redirect()->action('\\' . static::class . '@index', [$server->id])->with('message-success', $messages);
 }