2017-08-08 17:58:24 [149.154.167.211][-][6fe0406b78f22e1ae7c3c5bb160d2f27][error][yii\web\HttpException:400] exception 'yii\web\BadRequestHttpException' with message 'Не удалось проверить переданные данные.' in /home/users/h/holland-itkzn/domains/crm.holland-store/vendor/yiisoft/yii2/web/Controller.php:166
<?php
namespace frontend\controllers;
use app\models\User;
use frontend\components\TelegramComponent;
use yii\db\Exception;
use yii\web\Controller;
class TelegramController extends Controller
{
public function actionWebhook()
{
try{
$content = json_decode(file_get_contents('php://input'), true);
if(isset($data['message']['chat']['id']))
{
$chatId = $content['message']['chat']['id'];
$message = isset($data['message']['text']) ? $data['message']['text'] : false;
$send = false;
if (strpos($message, '/start') !== false) {
$explode = explode('', $message);
$token = isset($explode[1]) ? $explode[1] : false;
$data = [
'raw' => $token,
'chat_id' => $chatId,
];
$send = Telegram::start($data);
} else {
$send = 'Команда не найдена. Если Вы уверены в том, что ошибка, обратитесь в тех поддержку';
}
$send = $send ? '' : 'Что-то пошло не по плану. Обратитесь в тех.поддержку';
}
} catch (Exception $e){
$e->getMessage();
}
}
}
<?php
namespace frontend\models;
use common\models\User;
class Telegram
{
public static function start($data){
return self::login($data);
}
public static function login($data)
{
$token = $data['raw'];
if ($token && $user_id = User::findOne(['token' => $token])) {
$user = User::findOne($user_id->id);
if ($user->telegram_chat_id) {
return "Уважаемый $user->name, Вы уже авторизованы в системе. ";
}
$user->telegram_chat_id = $data['chat_id'];
$user->save();
return "Добро пожаловать, $user->first_name $user->last_name. Вы успешно авторизовались!";
} else {
return "Извините, не удалось найти данный токен!";
}
}
}
<?php
use aki\telegram\Telegram;
use app\models\User;
$bot = new Telegram();
$bot->setWebhook(['url' => 'https://crm.holland-store.ru/frontend/web/site/setting.php']);
$output = file_get_contents('php://input');
$id = $output['message']['chat']['id'];
file_put_contents('logs.txt', $id);
$token = '414134665:AAHfOIdeikQD04NdKckL8wadhqzggvmSqw0';
$model = User::findOne(\Yii::$app->user->id);
$model->telegram_chat_id = $id;
$model->save();
$webSite = 'https://api.telegram.org/bot'.$token;
public function actionSetting()
{
$output = json_decode(file_get_contents('php://input'), true);
$chat_id = $output['message']['chat']['id'];
$token = '414134665:AAHfOIdeikQD04NdKckL8wadhqzggvmSqw0';
file_put_contents('logs.txt', $chat_id);
$model = User::find()->where(['id' => Yii::$app->user->id])->one();
$model->telegram_chat_id = $chat_id;
$model->save();
// return $this->redirect('https://telegram.me/HollandSotrudbot');
}
public function actionTelegram()
{
return $this->redirect('https://telegram.me/HollandSotrudbot');
}