From fdd8395420989939c61f078745dd3df3fd2fd092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E4=B9=9D?= Date: Mon, 7 Jul 2025 14:00:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=9F=E5=90=8D=E5=A4=87=E6=A1=88=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.【新增】域名备案信息查询 --- app/controller/Domain.php | 33 +++++++++++ app/service/RecordCheckService.php | 94 ++++++++++++++++++++++++++++++ app/sql/update.sql | 6 +- app/view/domain/domain.html | 39 +++++++++++++ route/app.php | 1 + 5 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 app/service/RecordCheckService.php diff --git a/app/controller/Domain.php b/app/controller/Domain.php index ebc8e8e..f80cfe0 100644 --- a/app/controller/Domain.php +++ b/app/controller/Domain.php @@ -6,8 +6,10 @@ use app\BaseController; use think\facade\Db; use think\facade\View; use think\facade\Cache; +use think\facade\Request; use app\lib\DnsHelper; use app\service\ExpireNoticeService; +use app\service\RecordCheckService; use Exception; class Domain extends BaseController @@ -1094,4 +1096,35 @@ class Domain extends BaseController $result = (new ExpireNoticeService())->updateDomainDate($id, $drow['name']); return json($result); } + + public function refreshRecord() + { + $id = input('param.id/d'); + $drow = Db::name('domain')->where('id', $id)->find(); + + if (!$drow) { + return json(['code' => 1, 'msg' => '域名不存在']); + } + + try { + $service = new RecordCheckService(); + $result = $service->checkDomainRecord($drow['name'], $id); + + if ($result['code'] === 0 && isset($result['data'])) { + Db::name('domain') + ->where('id', $id) + ->strict(false) + ->update([ + 'record_status' => $result['data']['record_status'], + 'record_number' => $result['data']['record_number'] + ]); + + return json(['code' => 0, 'msg' => '刷新成功', 'data' => $result['data']]); + } else { + return json(['code' => 1, 'msg' => '查询失败']); + } + } catch (\Exception $e) { + return json(['code' => 1, 'msg' => '发生异常: ' . $e->getMessage()]); + } + } } diff --git a/app/service/RecordCheckService.php b/app/service/RecordCheckService.php new file mode 100644 index 0000000..8abb4d9 --- /dev/null +++ b/app/service/RecordCheckService.php @@ -0,0 +1,94 @@ +where('id', $id)->value('id'); + if (!$exists) { + return ['code' => -1, 'msg' => '域名不存在']; + } + + try { + $client = new Client(); + $response = $client->get($this->apiUrl, [ + 'query' => [ + 'token' => $this->token, + 'url' => $domain + ] + ]); + + $rawBody = $response->getBody()->getContents(); + + $encoding = mb_detect_encoding($rawBody, ['UTF-8', 'GBK', 'ASCII', 'ISO-8859-1'], true); + if ($encoding !== 'UTF-8') { + $rawBody = mb_convert_encoding($rawBody, 'UTF-8', $encoding); + } + + $result = json_decode($rawBody, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new Exception('JSON 解码失败: ' . json_last_error_msg()); + } + + if (isset($result['code']) && $result['code'] == 200 && !empty($result['data'])) { + $data = $result['data']; + + Db::name('domain') + ->where('id', $id) + ->strict(false) + ->update([ + 'record_status' => 1, + 'record_number' => $data['icp'], + ]); + + return [ + 'code' => 0, + 'data' => [ + 'record_status' => 1, + 'record_number' => $data['icp'] + ], + 'msg' => '备案查询成功' + ]; + } + + Db::name('domain') + ->where('id', $id) + ->strict(false) + ->update([ + 'record_status' => 2, + 'record_number' => null, + ]); + + return [ + 'code' => 0, + 'data' => [ + 'record_status' => 2, + 'record_number' => null + ], + 'msg' => '该域名暂未备案' + ]; + + } catch (Exception $e) { + Db::name('domain') + ->where('id', $id) + ->strict(false) + ->update([ + 'record_status' => 3, + ]); + + return [ + 'code' => -1, + 'msg' => '备案查询失败,请稍后再试' + ]; + } + } +} diff --git a/app/sql/update.sql b/app/sql/update.sql index 3c9db10..316cd1d 100644 --- a/app/sql/update.sql +++ b/app/sql/update.sql @@ -163,4 +163,8 @@ ADD COLUMN `regtime` datetime DEFAULT NULL, ADD COLUMN `expiretime` datetime DEFAULT NULL, ADD COLUMN `checktime` datetime DEFAULT NULL, ADD COLUMN `noticetime` datetime DEFAULT NULL, -ADD COLUMN `checkstatus` tinyint(1) NOT NULL DEFAULT '0'; \ No newline at end of file +ADD COLUMN `checkstatus` tinyint(1) NOT NULL DEFAULT '0'; + +ALTER TABLE `dnsmgr_domain` +ADD COLUMN `record_status` tinyint(1) NOT NULL DEFAULT '0', +ADD COLUMN `record_number` varchar(255) DEFAULT NULL; \ No newline at end of file diff --git a/app/view/domain/domain.html b/app/view/domain/domain.html index 7969e66..a8a78fb 100644 --- a/app/view/domain/domain.html +++ b/app/view/domain/domain.html @@ -279,6 +279,23 @@ $(document).ready(function(){ return value==1?'':''; } }, + { + field: 'record_number', + title: '备案信息', + formatter: function(value, row, index) { + if (row.record_status == 1) { + html = '' + value + ''; + } else if (row.record_status == 2) { + html = '暂无备案'; + } else if (row.record_status == 3) { + html = '查询失败'; + } else { + html = '待查询'; + } + html += ' '; + return html; + } + }, { field: 'remark', title: '备注' @@ -603,6 +620,28 @@ function updateDate(id){ } }); } +function refreshRecord(id) { + var ii = layer.load(2); + $.ajax({ + type: 'POST', + url: '/domain/refresh-record', + data: { id: id }, + dataType: 'json', + success: function (res) { + layer.close(ii); + if (res.code === 0) { + layer.msg('备案信息已更新', { icon: 1 }); + searchRefresh(); + } else { + layer.alert(res.msg || '刷新失败', { icon: 2 }); + } + }, + error: function () { + layer.close(ii); + layer.alert('请求失败,请重试', { icon: 2 }); + } + }); +} function loading(){ layer.load(2); } diff --git a/route/app.php b/route/app.php index 795b663..f63ca73 100644 --- a/route/app.php +++ b/route/app.php @@ -73,6 +73,7 @@ Route::group(function () { Route::post('/record/weight/data/:id', 'domain/weight_data'); Route::any('/record/weight/:id', 'domain/weight'); Route::get('/record/:id', 'domain/record'); + Route::post('domain/refresh-record', 'domain/refreshRecord'); Route::get('/dmonitor/overview', 'dmonitor/overview'); Route::post('/dmonitor/task/data', 'dmonitor/task_data');