From 72b66a3854104380326fbcc6a67122a911a3508d Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 15 Aug 2021 17:11:31 +0800 Subject: [PATCH] update: interface of send markdown --- functions/TgInterface.php | 7 +++++++ models/icpQuery.php | 16 ++++------------ models/ipInfo.php | 5 +---- models/kmsCheck.php | 6 ++---- models/ntpCheck.php | 6 ++---- models/punycode.php | 5 +---- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/functions/TgInterface.php b/functions/TgInterface.php index 1720924..fa2353e 100644 --- a/functions/TgInterface.php +++ b/functions/TgInterface.php @@ -5,6 +5,13 @@ class tgApi { return tgApi::sendMessage(['text' => $msg], $chatId); } + public function sendMarkdown($msg, $chatId = 0) { // 发送Markdown格式消息 + return tgApi::sendMessage(array( + 'text' => $msg, + 'parse_mode' => 'Markdown', + ), $chatId); + } + public function sendMessage($params, $chatId = 0) { // 发送消息 return tgApi::sendByMethod('sendMessage', $params, $chatId); } diff --git a/models/icpQuery.php b/models/icpQuery.php index a5ae65c..34666fc 100644 --- a/models/icpQuery.php +++ b/models/icpQuery.php @@ -119,20 +119,15 @@ class icpQueryEntry { } $content = $this->check($rawParam); if ($content['status'] !== 'ok') { // 请求参数错误 - tgApi::sendMessage(array( - 'parse_mode' => 'Markdown', - 'text' => $content['message'] - )); + tgApi::sendMarkdown($content['message']); return; } $isCache = true; $domain = $content['domain']; $msg = '`' . (new Punycode)->decode($domain) . '`' . PHP_EOL; if (!(new icpQuery)->isCache($domain)) { // 域名信息未缓存 - $message = json_decode(tgApi::sendMessage(array( - 'parse_mode' => 'Markdown', - 'text' => $msg . 'ICP备案信息查询中...' - )), true); + $message = tgApi::sendMarkdown($msg . 'ICP备案信息查询中...'); + $message = json_decode($message, true); $isCache = false; } $info = (new icpQuery)->icpInfo($domain); // 发起查询 @@ -178,10 +173,7 @@ class icpQueryEntry { $msg .= '*审核时间:*' . $info['VerifyTime'] . PHP_EOL; $msg .= '*许可证号:*' . $info['SiteLicense'] . PHP_EOL; if ($isCache) { // 没有缓冲信息 直接发送 - tgApi::sendMessage(array( // 返回查询数据 - 'parse_mode' => 'Markdown', - 'text' => $msg - )); + tgApi::sendMarkdown($msg); // 返回查询数据 } else { tgApi::editMessage(array( // 返回查询数据 修改原消息 'parse_mode' => 'Markdown', diff --git a/models/ipInfo.php b/models/ipInfo.php index 9eac1e4..c268e77 100644 --- a/models/ipInfo.php +++ b/models/ipInfo.php @@ -153,10 +153,7 @@ class ipInfoEntry { } $ips = $this->dnsResolve($rawParam); if (count($ips) == 0) { // 解析不到IP记录 - tgApi::sendMessage($chatId, array( - 'parse_mode' => 'Markdown', - 'text' => 'Nothing found of `' . $rawParam . '`' - )); + tgApi::sendMarkdown('Nothing found of `' . $rawParam . '`'); return; } foreach ($ips as $ip) { diff --git a/models/kmsCheck.php b/models/kmsCheck.php index 35c9249..7c43d25 100644 --- a/models/kmsCheck.php +++ b/models/kmsCheck.php @@ -205,10 +205,8 @@ class kmsCheckEntry { tgApi::sendText($check['message']); return; } - $message = json_decode(tgApi::sendMessage(array( - 'parse_mode' => 'Markdown', - 'text' => '`' . $rawParam . '`' . PHP_EOL . 'KMS服务检测中...' - )), true); + $message = tgApi::sendMarkdown('`' . $rawParam . '`' . PHP_EOL . 'KMS服务检测中...'); + $message = json_decode($message, true); fastcgi_finish_request(); // 断开连接 tgApi::editMessage(array( 'message_id' => $message['result']['message_id'], diff --git a/models/ntpCheck.php b/models/ntpCheck.php index 600549e..f134590 100644 --- a/models/ntpCheck.php +++ b/models/ntpCheck.php @@ -201,10 +201,8 @@ class ntpCheckEntry { tgApi::sendText('Illegal host'); // 输入错误 return; } - $message = json_decode(tgApi::sendMessage(array( - 'parse_mode' => 'Markdown', - 'text' => '`' . $rawParam . '`' . PHP_EOL . 'NTP Server Checking...' - )), true); + $message = tgApi::sendMarkdown('`' . $rawParam . '`' . PHP_EOL . 'NTP Server Checking...'); + $message = json_decode($message, true); fastcgi_finish_request(); // 断开连接 tgApi::editMessage(array( 'message_id' => $message['result']['message_id'], diff --git a/models/punycode.php b/models/punycode.php index d280cf9..1c4d7ae 100644 --- a/models/punycode.php +++ b/models/punycode.php @@ -45,10 +45,7 @@ class punycodeEntry { $msg .= '*Warning:* ' . $errMsg; } } - tgApi::sendMessage(array( - 'parse_mode' => 'Markdown', - 'text' => $msg - )); + tgApi::sendMarkdown($msg); } }