当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::getFile方法代码示例

本文整理汇总了PHP中Longman\TelegramBot\Request::getFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getFile方法的具体用法?PHP Request::getFile怎么用?PHP Request::getFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Longman\TelegramBot\Request的用法示例。


在下文中一共展示了Request::getFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 public function execute()
 {
     $update = $this->getUpdate();
     $message = $this->getMessage();
     $user_id = $message->getFrom()->getId();
     $chat_id = $message->getChat()->getId();
     $message_id = $message->getMessageId();
     $text = $message->getText(true);
     //send chat action
     Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
     $caption = 'Your Id: ' . $message->getFrom()->getId();
     $caption .= "\n" . 'Name: ' . $message->getFrom()->getFirstName() . ' ' . $message->getFrom()->getLastName();
     $caption .= "\n" . 'Username: ' . $message->getFrom()->getUsername();
     //Fetch user profile photo
     $limit = 10;
     $offset = null;
     $ServerResponse = Request::getUserProfilePhotos(['user_id' => $user_id, 'limit' => $limit, 'offset' => $offset]);
     //Check if the request isOK
     if ($ServerResponse->isOk()) {
         $UserProfilePhoto = $ServerResponse->getResult();
         $totalcount = $UserProfilePhoto->getTotalCount();
     } else {
         $totalcount = 0;
     }
     $data = [];
     $data['chat_id'] = $chat_id;
     $data['reply_to_message_id'] = $message_id;
     if ($totalcount > 0) {
         $photos = $UserProfilePhoto->getPhotos();
         //I pick the latest photo with the hight definition
         $photo = $photos[0][2];
         $file_id = $photo->getFileId();
         $data['photo'] = $file_id;
         $data['caption'] = $caption;
         $result = Request::sendPhoto($data);
         //Download the image pictures
         //Download after send message response to speedup response
         $file_id = $photo->getFileId();
         $ServerResponse = Request::getFile(['file_id' => $file_id]);
         if ($ServerResponse->isOk()) {
             Request::downloadFile($ServerResponse->getResult());
         }
     } else {
         //No Photo just send text
         $data['text'] = $caption;
         $result = Request::sendMessage($data);
     }
     return $result;
 }
开发者ID:KelvinVenancio,项目名称:php-telegram-bot,代码行数:49,代码来源:WhoamiCommand.php

示例2: execute

 /**
  * Command execute method
  *
  * @return mixed
  * @throws \Longman\TelegramBot\Exception\TelegramException
  */
 public function execute()
 {
     $message = $this->getMessage();
     $from = $message->getFrom();
     $user_id = $from->getId();
     $chat_id = $message->getChat()->getId();
     $message_id = $message->getMessageId();
     $data = ['chat_id' => $chat_id, 'reply_to_message_id' => $message_id];
     //Send chat action
     Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
     $caption = sprintf('Your Id: %d' . PHP_EOL . 'Name: %s %s' . PHP_EOL . 'Username: %s', $user_id, $from->getFirstName(), $from->getLastName(), $from->getUsername());
     //Fetch user profile photo
     $limit = 10;
     $offset = null;
     $response = Request::getUserProfilePhotos(['user_id' => $user_id, 'limit' => $limit, 'offset' => $offset]);
     if ($response->isOk()) {
         /** @var UserProfilePhotos $user_profile_photos */
         $user_profile_photos = $response->getResult();
         if ($user_profile_photos->getTotalCount() > 0) {
             $photos = $user_profile_photos->getPhotos();
             /** @var PhotoSize $photo */
             $photo = $photos[0][2];
             $file_id = $photo->getFileId();
             $data['photo'] = $file_id;
             $data['caption'] = $caption;
             $result = Request::sendPhoto($data);
             //Download the photo after send message response to speedup response
             $response2 = Request::getFile(['file_id' => $file_id]);
             if ($response2->isOk()) {
                 /** @var File $photo_file */
                 $photo_file = $response2->getResult();
                 Request::downloadFile($photo_file);
             }
             return $result;
         }
     }
     //No Photo just send text
     $data['text'] = $caption;
     return Request::sendMessage($data);
 }
开发者ID:akalongman,项目名称:php-telegram-bot,代码行数:46,代码来源:WhoamiCommand.php


注:本文中的Longman\TelegramBot\Request::getFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。