-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from CrazyTapok-bit/develop
Updated to new version and improved
- Loading branch information
Showing
18 changed files
with
230 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: Приклад коду | ||
icon: bolt | ||
index: false | ||
dir: | ||
order: 5 | ||
--- | ||
|
||
<Catalog /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: Віджет входу | ||
icon: right-to-bracket | ||
order: 2 | ||
head: | ||
- - meta | ||
- name: description | ||
content: Як перевірити дані користувача, отримані через Telegram Login Widget на PHP | ||
--- | ||
|
||
Ми намагаємось відобразити максимально повний приклад яким ви, скоріш за все, будете користуватись. | ||
|
||
```php | ||
<?php | ||
|
||
use TgWebValid\TgWebValid; | ||
use TgWebValid\Exceptions\BotException; | ||
use TgWebValid\Exceptions\ValidationException; | ||
use Exception; | ||
|
||
include './vendor/autoload.php'; | ||
|
||
try { | ||
/** | ||
* Вказую налаштування токена, та вмикаю роботу з винятками | ||
*/ | ||
$tgWebValid = new TgWebValid( | ||
token: 'TELEGRAM_BOT_TOKEN', | ||
throw: true | ||
); | ||
|
||
/** Налашту ще один додатковий бот щоб працювати з ними */ | ||
$tgWebValid->addBot( | ||
name: 'secondary', | ||
token: 'TELEGRAM_BOT_TOKEN_2' | ||
); | ||
|
||
/** Використаю бот за замовчуванням */ | ||
$bot = $tgWebValid->bot(); | ||
|
||
/** Або, вказую з яким ботом хочу працювати*/ | ||
$bot = $tgWebValid->bot( | ||
name: 'secondary' | ||
); | ||
|
||
/** | ||
* Викликаю метод validateLoginWidget який перевіре дані | ||
* отримані від Telegram Login Widget | ||
*/ | ||
$user = $bot->validateLoginWidget( | ||
user: [/** Дані користувача */] | ||
); | ||
|
||
/** Якщо перевірка успішна, виведу сутність LoginWidget з усіма даними */ | ||
var_dump($user); | ||
|
||
} catch (ValidationException $e) { | ||
// Отримаю виняток валідації якщо перевірку провалено | ||
} catch (BotException $e) { | ||
// Помилившись з назвою бота буду перехоплювати цей виняток | ||
} catch (Exception $e) { | ||
// Оброблю інші помилки, якщо такі будуть | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: Full example | ||
icon: bolt | ||
index: false | ||
dir: | ||
order: 5 | ||
--- | ||
|
||
<Catalog /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
title: Login Widget | ||
icon: right-to-bracket | ||
order: 2 | ||
head: | ||
- - meta | ||
- name: description | ||
content: How to validate data received via the Telegram Login Widget на PHP | ||
--- | ||
|
||
We try to display as complete an example as possible, which you will most likely use. | ||
|
||
```php | ||
<?php | ||
|
||
use TgWebValid\TgWebValid; | ||
use TgWebValid\Exceptions\BotException; | ||
use TgWebValid\Exceptions\ValidationException; | ||
use Exception; | ||
|
||
include './vendor/autoload.php'; | ||
|
||
try { | ||
/** | ||
* I specify the token settings and enable work with exceptions | ||
*/ | ||
$tgWebValid = new TgWebValid( | ||
token: 'TELEGRAM_BOT_TOKEN', | ||
throw: true | ||
); | ||
|
||
/** I will set up another additional bot to work with them */ | ||
$tgWebValid->addBot( | ||
name: 'secondary', | ||
token: 'TELEGRAM_BOT_TOKEN_2' | ||
); | ||
|
||
/** I use the default bot */ | ||
$bot = $tgWebValid->bot(); | ||
|
||
/** Or, specify which bot I want to work with */ | ||
$bot = $tgWebValid->bot( | ||
name: 'secondary' | ||
); | ||
|
||
/** | ||
* Call the validateLoginWidget method, | ||
* which checks the data received from the Telegram Login Widget | ||
*/ | ||
$user = $bot->validateLoginWidget( | ||
user: [/** Дані користувача */] | ||
); | ||
|
||
/** | ||
* If the check is successful, | ||
* I will display the LoginWidget entity with all user data | ||
*/ | ||
var_dump($user); | ||
|
||
} catch (ValidationException $e) { | ||
// I will get a validation exception if the check is failed | ||
} catch (BotException $e) { | ||
// Having made a mistake with the name of the bot, I will catch this exception | ||
} catch (Exception $e) { | ||
// I will process other errors if there are any | ||
} | ||
``` |
Oops, something went wrong.