summaryrefslogtreecommitdiff
path: root/localwebsite/classes
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-05-26 03:14:50 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-05-26 21:51:43 +0300
commitc3ed2483ea508141431be74f29f7c209271897cd (patch)
tree9f7a416ab433ffc9bd245d1dd382f350a4e61efc /localwebsite/classes
parent997c6da6c40c11ec0bc6cc749f78deca8dd95db1 (diff)
cron: vk sms checker
Diffstat (limited to 'localwebsite/classes')
-rw-r--r--localwebsite/classes/E3372.php2
-rw-r--r--localwebsite/classes/TelegramBotClient.php37
2 files changed, 39 insertions, 0 deletions
diff --git a/localwebsite/classes/E3372.php b/localwebsite/classes/E3372.php
index 538d387..9f21d02 100644
--- a/localwebsite/classes/E3372.php
+++ b/localwebsite/classes/E3372.php
@@ -176,8 +176,10 @@ class E3372
$messages = [];
foreach ($xml->Messages->Message as $message) {
+ $dt = DateTime::createFromFormat("Y-m-d H:i:s", (string)$message->Date);
$messages[] = [
'date' => (string)$message->Date,
+ 'timestamp' => $dt->getTimestamp(),
'phone' => (string)$message->Phone,
'content' => (string)$message->Content
];
diff --git a/localwebsite/classes/TelegramBotClient.php b/localwebsite/classes/TelegramBotClient.php
new file mode 100644
index 0000000..b9583ee
--- /dev/null
+++ b/localwebsite/classes/TelegramBotClient.php
@@ -0,0 +1,37 @@
+<?php
+
+class TelegramBotClient {
+
+ protected string $token;
+
+ public function __construct(string $token) {
+ $this->token = $token;
+ }
+
+ public function sendMessage(int $chat_id, string $text): bool {
+ $ch = curl_init();
+ $url = 'https://api.telegram.org/bot'.$this->token.'/sendMessage';
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, [
+ 'chat_id' => $chat_id,
+ 'text' => $text,
+ 'parse_mode' => 'html',
+ 'disable_web_page_preview' => 1
+ ]);
+ $body = curl_exec($ch);
+ curl_close($ch);
+
+ $resp = jsonDecode($body);
+ if (!$resp['ok']) {
+ debugError(__METHOD__ . ': ' . $body);
+ return false;
+ }
+
+ return true;
+ }
+
+} \ No newline at end of file