Пример #1
0
$phone = trim($_POST['phone']);
if (!preg_match("/^\\d{9,15}\$/", $phone)) {
    return Response::error('phone parameter does not seems a phone number');
}
$userStorage = new LocalFilesStorage('user');
$user = $userStorage->getById($phone);
if ($user) {
    return Response::error('phone exists already in this system');
}
$phoneRequested = isset($_SESSION['phone_requested']) ? json_decode($_SESSION['phone_requested'], true) : array();
if (isset($phoneRequested[$phone]) && intval(date("U")) < $phoneRequested[$phone]) {
    return Response::error('phone already requested, you must to wait 15 minutes');
}
$phoneRequested[$phone] = intval(date("U")) + 15 * 60 * 60;
$_SESSION['phone_requested'] = json_encode($phoneRequested);
$th = TelegramCliHelper::getInstance();
$t = new TelegramCliWrapper($th->getSocket(), $th->isDebug());
$user = User::createUser($phone, $phone, "");
$t->addContact($user);
// send message with code in order to validate phone
$r = uniqid();
$user->code = substr($r, rand(1, strlen($r) - 6), 6);
$userStorage->save($user);
$msg = <<<EOD
Welcome to the telegram-cli-wrapper proof of concept
This is the code to access system, please keep it secret.
Code: {$user->code}
*Note: If this message was not solicited by you, please do not take in account.
EOD;
$t->msg($user->phone, $msg);
return Response::ok();
Пример #2
0
<?php

include_once __DIR__ . '/../vendor/autoload.php';
use TelegramCliWrapper\TelegramCliWrapper;
use TelegramCliWrapper\TelegramCliHelper;
use TelegramCliWrapper\Models\User;
$th = TelegramCliHelper::getInstance();
$t = new TelegramCliWrapper($th->getSocket(), $th->isDebug());
echo "These are my contacts" . PHP_EOL . User::getTitles() . PHP_EOL;
$contacts = $t->getContactList();
foreach ($contacts as $contact) {
    echo $contact . PHP_EOL;
}
$t->quit();
Пример #3
0
<?php

if (!isset($argv[1])) {
    die("You have to call this program with the peer you want to see his info\n");
}
include_once __DIR__ . '/../vendor/autoload.php';
use TelegramCliWrapper\TelegramCliWrapper;
use TelegramCliWrapper\TelegramCliHelper;
use TelegramCliWrapper\Models\User;
$th = TelegramCliHelper::getInstance();
$t = new TelegramCliWrapper($th->getSocket(), $th->isDebug());
$peer = trim($argv[1]);
echo "The info for '{$peer}' is " . PHP_EOL . User::getTitles() . PHP_EOL . $t->getUserInfo($peer) . PHP_EOL;
$t->quit();
Пример #4
0
<?php

include_once __DIR__ . '/../vendor/autoload.php';
use TelegramCliWrapper\TelegramCliWrapper;
use TelegramCliWrapper\TelegramCliHelper;
use TelegramCliWrapper\Models\User;
$th = TelegramCliHelper::getInstance();
$t = new TelegramCliWrapper($th->getSocket(), $th->isDebug());
echo "These are my current dialogs" . PHP_EOL . User::getTitles() . PHP_EOL;
$currentDialogs = $t->getDialogList();
foreach ($currentDialogs as $currentDialog) {
    echo $currentDialog . PHP_EOL;
}
$t->quit();
Пример #5
0
<?php

include_once __DIR__ . '/../vendor/autoload.php';
use TelegramCliWrapper\TelegramCliWrapper;
use TelegramCliWrapper\TelegramCliHelper;
use TelegramCliWrapper\Models\User;
$th = TelegramCliHelper::getInstance();
$t = new TelegramCliWrapper($th->getSocket(), $th->isDebug());
echo "this is me" . PHP_EOL . User::getTitles() . PHP_EOL . $t->whoAmI() . PHP_EOL;
$t->quit();
 /**
  * @return User[]
  */
 public function getContactList()
 {
     return User::fromArray($this->contact_list());
 }