Доброе (current) время суток, Anton!
OR>> Parse error: syntax error, unexpected 'use' (T_USE) in
OR>> /home/tuder/public_html/telegram/gc/functions.php on line 84
AP> Я не вижу код, но line 84 наталкивает на мысль о том, что use
AP> расположен где-то кроме начала, где ему положено быть.
=== Вырезка из филе bot.php ===
<?php
//задаём наш токен, полученный при создании бота и указываем путь к API
телеграма
define('BOT_TOKEN', '389260357:EAA5b7EMUf6HWv14OR6RDr-_Sk90Xv-9Iq0');
define('API_URL', '
https://api.telegram.org/bot' . BOT_TOKEN . '/');
include_once './functions.php';
//принимаем запрос от бота(то что напишет в чате пользователь)
$content = file_get_contents('php://input');
//превращаем из json в массив
$update = json_decode($content, TRUE);
//получаем id чата
$chat_id = $update['message']['chat']['id'];
//получаем текст запроса
$text = $update['message']['text'];
//обработка запроса
getUserRequest($text, $chat_id);
?>
=== Кончилась врезка ===
Тут я убрал все отладочные выводы, так что номер строки с use не совпадает.
Но если убрать строку с use, то выдаётся
Fatal error: Class 'Client' not found in
/home/tuder/public_html/telegram/gc/functions.php on line 89
Собственно в примере не было use. Нашёл аналогчиный пример, где use сразу
после инклюда вендора. Подставил. Не помогло. :-\
=== Вырезка из филе functions.php ===
<?php
function getUserRequest($text, $chat_id) {
/*
$resp = commIsHello($text);
if (!empty($resp)) {
$resp['chat_id'] = $chat_id;
requestToTelegram($resp);
return TRUE;
}
*/
$resp = commIsUser($text);
if (!empty($resp)) {
$resp['chat_id'] = $chat_id;
requestToTelegram($resp);
return TRUE;
}
}
//проверка на ник
function commIsUser($text) {
$text = trim($text);//обрезаем пробелы в начале и в конце
$space = strpos($text, ' ');
if (($space === FALSE) && (mb_substr($text, 0, 1) == '@')) {
//возможно это ник пользователя
//подключаемся к блокчейну
_require('vendor/autoload.php');_
#use WebSocket/Client;#
$client = new Client("wss://
ws.golos.io/");
$req = json_encode(
[
'id' => 1, 'method' => 'get_accounts', 'params' => [[mb_substr($text,
'id' => 1)]]
]
);
$client->send($req);
$golos_resp = $client->receive();
$resp_object = json_decode($golos_resp);
if (!empty($resp_object->result)) {
$obj = $resp_object->result[0];
$user = array();
$user[] = 'ID: ' . $obj->id;
$user[] = 'Логин: ' . $obj->name;
$user[] = 'Аккаунт создан: ' . $obj->created;
$user[] = 'Последний раз голосовал: ' . $obj->last_vote_time;
$user[] = 'Создано постов: ' . $obj->post_count;
//расчёт репутации
$reputation = $obj->reputation;
$user[] = 'Репутация: ' . round((max(log10(abs($reputation)) - 9,0) *
(($reputation
>= 0) ? 1 : -1) * 9 + 25), 3);
$json_metadata = json_decode($obj->json_metadata);
if (!empty($json_metadata->user_image)) {
//фото
// передавать не буду, так как у некоторых логинов "заколдованные"
аватары и сообщение в телеграм не приходит
// $user[] = 'Аватар: ' . $json_metadata->user_image;
}
$text = implode("\n", $user);
$data = array(
'text' => $text,
'parse_mode' => 'Markdown',
);
}
else {
$data = array(
'text' => 'Пользователь не найден.',
);
}
$client->close();
if (!empty($data)) {
return $data;
}
}
return NULL;
}
//отправка запроса в чат
function requestToTelegram($data, $type = 'sendMessage') {
if( $curl = curl_init() ) {
curl_setopt($curl, CURLOPT_URL, API_URL . $type);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_exec($curl);
curl_close($curl);
}
}
?>
=== Кончилась врезка ===