Trying to make sendCode work

This commit is contained in:
Daniil Gentili 2016-10-18 14:44:44 +00:00
parent 2badf3f35e
commit d1e7cce35b
5 changed files with 25 additions and 6 deletions

View File

@ -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->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', [ $nearestDc = $this->method_call('invokeWithLayer', [
'layer' => $this->settings['tl_schema']['layer'], 'layer' => $this->settings['tl_schema']['layer'],
'query' => $this->tl->serialize_method('initConnection', 'query' => $this->tl->serialize_method('initConnection',
@ -151,7 +162,6 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
$this->connection->dc_connect($nearestDc['nearest_dc']); $this->connection->dc_connect($nearestDc['nearest_dc']);
} }
} }
public function __destruct() public function __destruct()
{ {
unset($this->sock); unset($this->sock);

View File

@ -458,4 +458,9 @@ class AuthKeyHandler extends AckHandler
throw new Exception('Auth Failed'); throw new Exception('Auth Failed');
} }
public function bind_temp_auth_key($expires_in = 86400) {
$nonce = $this->struct->unpack('<q', \phpseclib\Crypt\Random::string(8));
$expires_at = time() + $expires_in;
}
} }

View File

@ -91,10 +91,14 @@ class TL extends \danog\MadelineProto\Tools
$bytes_io .= $this->struct->pack('<i', $tl_method->id); $bytes_io .= $this->struct->pack('<i', $tl_method->id);
foreach ($tl_method->params as $arg) { foreach ($tl_method->params as $arg) {
if (!isset($kwargs[$arg['name']])) { if (!isset($kwargs[$arg['name']])) {
if ($arg['opt']) { if ($arg['name'] == 'flags') {
continue; $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']]); $bytes_io .= $this->serialize_param($arg['type'], $arg['subtype'], $kwargs[$arg['name']]);
} }

View File

@ -22,7 +22,7 @@ class TLConstructor
$this->params = $json_dict['params']; $this->params = $json_dict['params'];
foreach ($this->params as &$param) { foreach ($this->params as &$param) {
$param['opt'] = false; $param['opt'] = false;
$param['subtype'] = ''; $param['subtype'] = null;
if (preg_match('/^flags\.\d\?/', $param['type'])) { if (preg_match('/^flags\.\d\?/', $param['type'])) {
$param['opt'] = true; $param['opt'] = true;
$param['flag'] = preg_replace(['/^flags\./', '/\?.*/'], '', $param['type']); $param['flag'] = preg_replace(['/^flags\./', '/\?.*/'], '', $param['type']);

View File

@ -22,7 +22,7 @@ class TLMethod
$this->params = $json_dict['params']; $this->params = $json_dict['params'];
foreach ($this->params as &$param) { foreach ($this->params as &$param) {
$param['opt'] = false; $param['opt'] = false;
$param['subtype'] = ''; $param['subtype'] = null;
if (preg_match('/^flags\.\d\?/', $param['type'])) { if (preg_match('/^flags\.\d\?/', $param['type'])) {
$param['opt'] = true; $param['opt'] = true;
$param['flag'] = preg_replace(['/^flags\./', '/\?.*/'], '', $param['type']); $param['flag'] = preg_replace(['/^flags\./', '/\?.*/'], '', $param['type']);