diff --git a/README.md b/README.md index 358423c..39266db 100644 --- a/README.md +++ b/README.md @@ -98,10 +98,10 @@ Fast, simple, async php telegram client and parser: MadelineProto + Swoole Serve You can add client ip in .env file to `API_CLIENT_WHITELIST` (use json format) Examples: - * get_info about channel/user: `http://127.0.0.1:9503/api/getInfo/?id=@xtrime` - * repost: `http://127.0.0.1:9503/api/forwardMessages/?fromPeer=@xtrime&toPeer=@xtrime&messageId=1234` + * get_info about channel/user: `http://127.0.0.1:9503/api/getInfo/?data[id]=@xtrime` + * repost: `http://127.0.0.1:9503/api/forwardMessages/?data[fromPeer]=@xtrime&data[toPeer]=@xtrime&data[messageId]=1234` * get messages from channel/user: `http://127.0.0.1:9503/api/getHistory/?data[peer]=@breakingmash&data[limit]=10` - * search: `http://127.0.0.1:9503/api/searchGlobal/?q=Hello%20World&limit=10` + * search: `http://127.0.0.1:9503/api/searchGlobal/?data[q]=Hello%20World&data[limit]=10` * sendMessage: `http://127.0.0.1:9503/api/sendMessage/?data[peer]=@xtrime&data[message]=Hello!` **Contacts** diff --git a/src/Client.php b/src/Client.php index 9406e5f..07aabf1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -34,13 +34,21 @@ class Client { /** * Получает данные о канале/пользователе по логину * - * @param array|string|id $id - * Например логин в формате '@xtrime' + * @param array $data + *
+ * $data = [ + * 'id' => , array|string, Например логин в формате '@xtrime' + * ]; + *+ * * @return array */ - public function getInfo($id): array + public function getInfo($data): array { - return $this->MadelineProto->get_info((string)$id); + $data = array_merge([ + 'id' => '', + ], $data); + return $this->MadelineProto->get_info($data['id']); } @@ -81,33 +89,32 @@ class Client { /** * Пересылает сообщения * - * @param string $fromPeer - * @param string $toPeer - * @param array|int $messageId + * @param array $data * Id сообщения, или нескольких сообщений */ - public function forwardMessages($fromPeer, $toPeer, $messageId): void + public function forwardMessages($data): void { - $this->MadelineProto->messages->forwardMessages([ - 'from_peer' => $fromPeer, - 'to_peer' => $toPeer, - 'id' => (array) $messageId, - ]); + $data = array_merge([ + 'from_peer' => '', + 'to_peer' => '', + 'id' => [], + ],$data); + $this->MadelineProto->messages->forwardMessages($data); } /** - * @param string $q - * @param int $limit + * @param array $data * @return array */ - public function searchGlobal($q = '', $limit = 10): array + public function searchGlobal(array $data): array { - return $this->MadelineProto->messages->searchGlobal([ - 'q' => $q, + $data = array_merge([ + 'q' => '', 'offset_id' => 0, 'offset_date' => 0, - 'limit' => $limit, - ]); + 'limit' => 10, + ],$data); + return $this->MadelineProto->messages->searchGlobal($data); } /** diff --git a/src/RequestCallback.php b/src/RequestCallback.php index fb86b55..f5ba35b 100644 --- a/src/RequestCallback.php +++ b/src/RequestCallback.php @@ -165,6 +165,9 @@ class RequestCallback if (!in_array($request->server['remote_addr'], $this->ipWhiteList, true)) { throw new \Exception('API not available'); } + if (!method_exists($this->parser->client,$this->api)) { + throw new \Exception('api not found'); + } $this->page['response'] = $this->parser->client->{$this->api}(...$this->parameters); break; case 'json':