EIOS/whtg/function.php

101 lines
3.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
function sendMessage($data){//Отправка Сообщения
if(!count($data)) {
$data['getQuery'] = array(
"chat_id" => $data['chat_id'],
"text" => "Новое сообщение из формы",
"parse_mode" => "html",
);
}
$data['apiurl'] = 'sendMessage';
$rez = cCurl($data);
}
function reply_to_message_id($data){//Отправка ответа на сообщение
if(!count($data)) {
$data['apiurl'] = 'reply_to_message_id';
$data['getQuery'] = array(
"chat_id" => $data['chat_id'],
"text" => "Новое сообщение из формы",
"parse_mode" => "html",
"reply_to_message_id" => 7
);
}
$rez = cCurl($data);
}
function deleteMessage($data){//Удаление сообщений из чата
if(!count($data)) {
$data['apiurl'] = 'deleteMessage';
$data['getQuery'] = array(
"chat_id" => $data['chat_id'],
"message_id" => 32456,
);
}
$rez = cCurl($data);
}
/* для получения данных о файле */
function TG_getFile($data) {
$data['apiurl'] = 'getFile';
$rez = cCurl($data);
return $rez;
}
function setWebhook($data){
$data['getQuery'] = array(
"url" => 'https://'.$_SERVER['HTTP_HOST'].'/whtg/tg8hook.php'
);
$data['apiurl'] = 'setWebhook';
$rez = cCurl($data);
return $rez;
//{
// "ok": true,
// "result": true,
// "description": "Webhook was set"
//}
}
function cCurl($data1){//Отправка в ТЕЛЕГРАММ данных
GLOBAL $conf;
if(!isset($data1['token'])) $data1['token'] = $conf['token'];
$ch = curl_init("https://api.telegram.org/bot" . $data1['token'] . "/".$data1['apiurl']."?" . http_build_query($data1['getQuery']));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
$resultQuery = curl_exec($ch);
curl_close($ch);
return $resultQuery;
//ОТВЕТ{
// "ok": true,
// "result": {
// "message_id": 12,
// "from": {
// "id": 5340791844,
// "is_bot": true,
// "first_name": "test_prog_time",
// "username": "test_prog_time_bot"
// },
// "chat": {
// "id": 1424646511,
// "first_name": "Илья",
// "last_name": "Лящук",
// "username": "iliyalyachuk",
// "type": "private"
// },
// "date": 1658907913,
// "text": "Новое сообщение из формы"
// }
//}
}
function writeLogFile($string, $clear = false){//Запись в файл
$log_file_name = __DIR__."/message.txt";
$now = date("Y-m-d H:i:s");
if($clear == false) {
file_put_contents($log_file_name, $now." ".print_r($string, true)."\r\n", FILE_APPEND);
}
else {
file_put_contents($log_file_name, '');
file_put_contents($log_file_name, $now." ".print_r($string, true)."\r\n", FILE_APPEND);
}
}