From d1e7cce35bc80f61c52eb183ee2d10a916a37d24 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 18 Oct 2016 14:44:44 +0000 Subject: [PATCH] Trying to make sendCode work --- src/danog/MadelineProto/MTProto.php | 12 +++++++++++- .../MadelineProto/MTProtoTools/AuthKeyHandler.php | 5 +++++ src/danog/MadelineProto/TL/TL.php | 10 +++++++--- src/danog/MadelineProto/TL/TLConstructor.php | 2 +- src/danog/MadelineProto/TL/TLMethod.php | 2 +- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index dcc7c3ae..6de09a6a 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -134,7 +134,18 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB } $this->settings['authorization']['temp_auth_key'] = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in']); } + $this->write_client_info(); + $nearestDc = $this->method_call('auth.sendCode', [ + 'phone_number' => '393373737', + 'sms_type' => 5, + 'api_id' => $this->settings['app_info']['api_id'], + 'api_hash' => $this->settings['app_info']['api_hash'], + 'lang_code' => $this->settings['app_info']['lang_code'], + ]); +var_dump($nearestDc); + } + public function write_client_info() { $nearestDc = $this->method_call('invokeWithLayer', [ 'layer' => $this->settings['tl_schema']['layer'], 'query' => $this->tl->serialize_method('initConnection', @@ -151,7 +162,6 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB $this->connection->dc_connect($nearestDc['nearest_dc']); } } - public function __destruct() { unset($this->sock); diff --git a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php index 572adc6c..79764b00 100644 --- a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php @@ -458,4 +458,9 @@ class AuthKeyHandler extends AckHandler throw new Exception('Auth Failed'); } + public function bind_temp_auth_key($expires_in = 86400) { + $nonce = $this->struct->unpack('struct->pack('id); foreach ($tl_method->params as $arg) { if (!isset($kwargs[$arg['name']])) { - if ($arg['opt']) { - continue; + if ($arg['name'] == 'flags') { + $kwargs['flags'] = 0; + } else { + if ($arg['opt']) { + continue; + } + throw new Exception('Missing required parameter ('.$arg['name'].')'); } - throw new Exception('Missing required parameter ('.$arg['name'].')'); } $bytes_io .= $this->serialize_param($arg['type'], $arg['subtype'], $kwargs[$arg['name']]); } diff --git a/src/danog/MadelineProto/TL/TLConstructor.php b/src/danog/MadelineProto/TL/TLConstructor.php index 3e1ea9fa..71860ce4 100644 --- a/src/danog/MadelineProto/TL/TLConstructor.php +++ b/src/danog/MadelineProto/TL/TLConstructor.php @@ -22,7 +22,7 @@ class TLConstructor $this->params = $json_dict['params']; foreach ($this->params as &$param) { $param['opt'] = false; - $param['subtype'] = ''; + $param['subtype'] = null; if (preg_match('/^flags\.\d\?/', $param['type'])) { $param['opt'] = true; $param['flag'] = preg_replace(['/^flags\./', '/\?.*/'], '', $param['type']); diff --git a/src/danog/MadelineProto/TL/TLMethod.php b/src/danog/MadelineProto/TL/TLMethod.php index 2d2b9765..5809303e 100644 --- a/src/danog/MadelineProto/TL/TLMethod.php +++ b/src/danog/MadelineProto/TL/TLMethod.php @@ -22,7 +22,7 @@ class TLMethod $this->params = $json_dict['params']; foreach ($this->params as &$param) { $param['opt'] = false; - $param['subtype'] = ''; + $param['subtype'] = null; if (preg_match('/^flags\.\d\?/', $param['type'])) { $param['opt'] = true; $param['flag'] = preg_replace(['/^flags\./', '/\?.*/'], '', $param['type']);